当前位置: 首页>>代码示例>>C#>>正文


C# Database.SaveChanges方法代码示例

本文整理汇总了C#中Database.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Database.SaveChanges方法的具体用法?C# Database.SaveChanges怎么用?C# Database.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Database的用法示例。


在下文中一共展示了Database.SaveChanges方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Edit

        public ActionResult Edit(int id, string jsonp, string callback)
        {
            using (var db = new Database())
            {
                try
                {
                    var model = db.JsonItems.Find(id);
                    if (model == null)
                        throw new Exception();

                    //timestamp
                    model.Viewed = DateTime.UtcNow;
                    db.SaveChanges();

                    if (!(String.IsNullOrEmpty(jsonp) && String.IsNullOrEmpty(callback)))
                    {
                        var _jsonp = jsonp ?? callback;
                        return Content(String.Format("{0}({1})",_jsonp, model.Json));
                    }

                    return View(model);
                }
                catch (Exception)
                {
                    return RedirectToAction("Create");
                }
            }
        }
开发者ID:Tabaka,项目名称:JSONShare,代码行数:28,代码来源:HomeController.cs

示例2: History

 public ActionResult History()
 {
     var database = new Database();
     var dateTime = DateTime.Now;
     string Uname = (string)Session["userName"];
     database.Histories.Add(new History { Uname = "oleh", LastActivity = dateTime.ToLongDateString() + dateTime.ToLongTimeString(), ActivityType = "Watched history" });
     database.SaveChanges();
     return View("History");
 }
开发者ID:Fatum94,项目名称:Perewant,代码行数:9,代码来源:HomeController.cs

示例3: LogOut

 public ActionResult LogOut()
 {
     HttpCookie myCookie = new HttpCookie("auth_test");
     var database = new Database();
     var dateTime = DateTime.Now;
     string Uname = (string)Session["userName"];
     database.Histories.Add(new History { Uname = "oleh", LastActivity = dateTime.ToLongDateString() + dateTime.ToLongTimeString(), ActivityType = "Logged Out" });
     database.SaveChanges();
     myCookie.Expires = DateTime.Now.AddDays(-1d);
     Response.Cookies.Add(myCookie);
     Session.Clear();
     return RedirectToAction("Register");
 }
开发者ID:Fatum94,项目名称:Perewant,代码行数:13,代码来源:HomeController.cs

示例4: Create

        public ActionResult Create([Bind(Exclude="Id")]JsonItem item)
        {
            if (ModelState.IsValid)
            {
                using (var db = new Database())
                {
                    item.Json = item.Json.Trim();
                    //timestamp
                    item.Created = DateTime.UtcNow;
                    item.Updated = DateTime.UtcNow;

                    db.JsonItems.Add(item);
                    db.SaveChanges();
                    return RedirectToAction("Edit", new { id = item.Id });
                }
            }
            return View(item);
        }
开发者ID:Tabaka,项目名称:JSONShare,代码行数:18,代码来源:HomeController.cs

示例5: ProcessCSV

        private void ProcessCSV(string fileName)
        {
            var database = new Database();

            //Set up our variables
            string Feedback = string.Empty;
            string line = string.Empty;
            string[] strArray = { "", "", "", "" };
            // work out where we should split on comma, but not in a sentence
            Regex r = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
            //Set the filename in to our stream
            var sr = new StreamReader(fileName);
            while ((line = sr.ReadLine()) != null)
            {

                //add our current value to our data row
                strArray = r.Split(line);

                database.Compressor.Add(new Kompressor { PressIn = strArray[0], PressOut = strArray[1], Performance = strArray[2], Rodo = strArray[3] });
                database.SaveChanges();
            }
        }
开发者ID:Fatum94,项目名称:Lab3BR,代码行数:22,代码来源:HomeController.cs

示例6: Register

 public ActionResult Register(User user)
 {
     try
     {
         var database = new Database();
         user.isAuth = true;
         database.Users.Add(user);
         database.SaveChanges();
         return Json(new { success = true }, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex) {
         return Json( new {error = ex.Message}, JsonRequestBehavior.AllowGet);
     }
 }
开发者ID:Fatum94,项目名称:Perewant,代码行数:14,代码来源:HomeController.cs

示例7: ProcessCSV

        private void ProcessCSV(HttpPostedFileBase FileUpload)
        {
            var database = new Database();
            var dateTime = DateTime.Now;
            string Uname = (string)Session["userName"];
            database.Histories.Add(new History { Uname = "oleh", LastActivity = dateTime.ToLongDateString() + dateTime.ToLongTimeString(), ActivityType = "Uploaded file to database" });
            database.SaveChanges();
            //Set up our variables
            string Feedback = string.Empty;
            string line = string.Empty;

            string [] strArray;
            // work out where we should split on comma, but not in a sentence
            Regex r = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
            //Set the filename in to our stream
            using (var sr = new StreamReader(FileUpload.InputStream))
            {
                while ((line = sr.ReadLine()) != null)
                {

                    //add our current value to our data row
                    strArray = r.Split(line);
                    var PressIn = strArray[0];
                    var PressOut = strArray[1];
                    var Performance = strArray[2];
                    var Drive = strArray[3];
                    var Power = strArray[4];
                    var DegreesOfPressure = strArray[5];
                    var NumberOfCylinders = strArray[6];
                    var Bore = strArray[7];
                    var LengthOfStroke = strArray[8];
                    var SpeedOfRotation = strArray[9];
                    var fromDB =
                        database.Compressor.Where(c=>
                            c.PressIn ==
                            PressIn && c.PressOut ==
                                    PressOut && c.Performance ==
                                        Performance && c.Drive ==
                                            Drive && c.Power ==
                                                Power && c.DegreesOfPressure ==
                                                    DegreesOfPressure && c.NumberOfCylinders ==
                                                        NumberOfCylinders && c.Bore ==
                                                            Bore && c.LengthOfStroke ==
                                                                LengthOfStroke && c.SpeedOfRotation == SpeedOfRotation).FirstOrDefault();
                    if (fromDB == null)
                    {
                        database.Compressor.Add(new Kompressor
                        {
                            PressIn = strArray[0],
                            PressOut = strArray[1],
                            Performance = strArray[2],
                            Drive = strArray[3],
                            Power = strArray[4],
                            DegreesOfPressure = strArray[5],
                            NumberOfCylinders = strArray[6],
                            Bore = strArray[7],
                            LengthOfStroke = strArray[8],
                            SpeedOfRotation = strArray[9]
                        });
                        database.SaveChanges();
                    }
                    fromDB = null;

                }
            }
        }
开发者ID:Fatum94,项目名称:Perewant,代码行数:66,代码来源:HomeController.cs

示例8: WatchDB

        public ActionResult WatchDB(User user)
        {
            try
            {

                    var database = new Database();
                    var dateTime = DateTime.Now;
                    string Uname = (string)Session["userName"];
                    database.Histories.Add(new History { Uname = "oleh", LastActivity = dateTime.ToLongDateString() + dateTime.ToLongTimeString(), ActivityType = "Logged in" });
                    database.SaveChanges();
                    var userLine = database.Users.Where(u => u.Name == user.Name).FirstOrDefault();
                    if (userLine.Password == user.Password)
                    {
                        var hash = Convert.ToBase64String(
                              System.Security.Cryptography.MD5.Create()
                              .ComputeHash(Encoding.UTF8.GetBytes(userLine.Password))
                            );

                        var AuthCookie = new HttpCookie("auth_test")
                        {
                            Value = hash + "id" + userLine.Id,
                            Expires = DateTime.Now.Add(FormsAuthentication.Timeout)
                        };
                        user.isAuth = true;
                        HttpContext.Response.Cookies.Set(AuthCookie);
                        Session["userRole"] = userLine.Role;
                        Session["userName"] = userLine.Name;
                    }
                    return Json(new { success = true, url = "/" });

            }
            catch (InvalidCastException e)
            {
                return RedirectToAction("Register");
            }
            return Json(new { success = true });
        }
开发者ID:Fatum94,项目名称:Perewant,代码行数:37,代码来源:HomeController.cs

示例9: SelectCompressor

 public ActionResult SelectCompressor(ViewModel model)
 {
     var database = new Database();
     var dateTime = DateTime.Now;
     string Uname = (string)Session["userName"];
     database.Histories.Add(new History { Uname = "oleh", LastActivity = dateTime.ToLongDateString() + dateTime.ToLongTimeString(), ActivityType = "Selected compressor" });
     database.SaveChanges();
     var compressor = database.Compressor.Where(c => c.PressIn == model.First.PressIn);
     return Json(new {resp = compressor, success = true}, JsonRequestBehavior.AllowGet);
 }
开发者ID:Fatum94,项目名称:Perewant,代码行数:10,代码来源:HomeController.cs


注:本文中的Database.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。