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


C# DB.SaveChanges方法代码示例

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


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

示例1: clearLine

        protected string clearLine()
        {
            bool result = false;
            string line = Request.Form["line"];

            if (!string.IsNullOrEmpty(line) && line != "all")
            {
                using (DB db = new DB())
                {
                    List<DowntimeData> list = (from o in db.DowntimeDataSet
                                               where o.Client == "admin"
                                               && o.Line == line
                                               select o).ToList();

                    if (list.Count() > 0)
                    {
                        foreach (DowntimeData dt in list)
                        {
                            db.DeleteObject(dt);
                        }
                    }

                    result = db.SaveChanges() > 0;
                }
            }

            return result.ToString();
        }
开发者ID:bsimp6983,项目名称:BackupDashes,代码行数:28,代码来源:TvDemoControl.aspx.cs

示例2: Index

        //
        // GET: /Home/
        public ActionResult Index()
        {
            DB context = new DB();

            var l = new List<User>()
            {
                new User() { Email = "[email protected]" },
            };
            l.ForEach(r => context.Users.Add(r));

            context.SaveChanges();

            return View();
        }
开发者ID:ghostnguyen,项目名称:226d56c4-9027-4e9d-a8cb-b679017efbed,代码行数:16,代码来源:HomeController.cs

示例3: Add

        public ActionResult Add(Data form)
        {
            using (DB db = new DB())
            {
                bool repeat = db.data.Count(q => q.en_word.Equals(form.en_word)) != 0;
                if (repeat)
                {
                    TempData["status"] = "Add faild, en_word exist.";
                    return RedirectToAction("Index");
                }

                db.data.Add(form);
                db.SaveChanges();
                TempData["status"] = "Add success.";

                return RedirectToAction("Index");
            }
        }
开发者ID:WindOfNet,项目名称:ENWord,代码行数:18,代码来源:CreateController.cs

示例4: FacebookRedirect


//.........这里部分代码省略.........
                    }
                }

                Session["FacebookAccessToken"] = accessToken;

                string meUrl = "https://graph.facebook.com/me?access_token={0}";
                request = WebRequest.Create(string.Format(meUrl, accessToken));
                using (WebResponse response = request.GetResponse())
                using (Stream stream = response.GetResponseStream())
                {
                    Encoding encode = Encoding.GetEncoding("utf-8");
                    using (StreamReader streamReader = new StreamReader(stream, encode))
                    {
                        var userDict = JsonConvert.DeserializeObject<IDictionary<String, Object>>(streamReader.ReadToEnd());
                        facebookID = userDict["id"] as string;
                        name = userDict["name"] as string;
                        isVerified = (bool) userDict["verified"];
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error("facebook graph error, token:" + accessToken, e);
            }

            if (facebookID != null)
            {
                using (DB db = new DB())
                {
                    InvitationToken invitationToken = null;
                    if (!string.IsNullOrWhiteSpace(token))
                    {
                        token = token.Trim();
                        invitationToken = db.InvitationTokens.FirstOrDefault(t => t.Token == token && !t.IsUsed);
                    }

                    var user = db.Users.FirstOrDefault(u => u.FacebookId == facebookID && u.IsActive);
                    if(invitationToken != null)
                    {
                        using (var tx = db.Database.BeginTransaction())
                        {
                            invitationToken.IsUsed = true;
                            db.Entry(invitationToken).State = EntityState.Modified;
                            if (user != null)
                            {
                                user.IsADuplicate = true;
                                user.IsActive = false;
                                user.UserName = "inactive" + user.Id.Replace("-", "");
                                db.Entry(user).State = EntityState.Modified;

                                foreach (var spreadsheet in db.Set<Spreadsheet>().Where(d => d.fkCreatedById == user.Id))
                                {
                                    spreadsheet.fkCreatedById = invitationToken.fkUserId;
                                    db.Entry(spreadsheet).State = EntityState.Modified;
                                }
                                foreach (var spreadsheet in db.Set<Spreadsheet>().Where(d => d.fkApprovedById == user.Id))
                                {
                                    spreadsheet.fkApprovedById = invitationToken.fkUserId;
                                    db.Entry(spreadsheet).State = EntityState.Modified;
                                }
                            }
                            user = invitationToken.User;
                            user.IsActive = true;
                            user.FacebookId = facebookID;
                            user.Name = name;

                            db.SaveChanges();
                            tx.Commit();
                        }
                    }

                    if (user == null)
                    {
                        using (var tx = db.Database.BeginTransaction())
                        {
                            var userManager = new UserManager<User>(new CUserStore<User>(db));
                            user = new User
                            {
                                FacebookId = facebookID,
                                Name = name,
                                IsActive = true,
                                UserName = "fb" + facebookID,
                                Id = Guid.NewGuid().ToString(),
                                FacebookIsVerified = isVerified
                            };
                            var newUser = userManager.Create(user);
                            userManager.AddToRole(user.Id, Role.VOLUNTEER);
                            tx.Commit();
                        }
                    }

                    Session[USERID_KEY] = user.Id;
                }
            }

            if(!string.IsNullOrEmpty(exAuthState))
                return new RedirectResult("/AuthTokenGet?state="+exAuthState);

            return new RedirectResult(loginRedirect);
        }
开发者ID:ekospinach,项目名称:kawaldesa,代码行数:101,代码来源:KawalDesaController.cs

示例5: stopEvent

        protected string stopEvent()
        {
            int time = 0;

            int.TryParse(Request.Form["time"], out time);

            string line = Request.Form["line"];
            int intLine = 0;
            int.TryParse(line, out intLine);

            decimal minutes = time;

            DateTime startdatetime = DateTime.Now;
            DateTime enddatetime = DateTime.Now.AddMinutes((double)minutes);

            /*
            DowntimeReason downtime = DCSDashboardDemoHelper.GetRandomReason("admin");

            string reason = downtime.Level1;

            if (!string.IsNullOrEmpty(downtime.Level2))
                reason += " > " + downtime.Level2;

            if (!string.IsNullOrEmpty(downtime.Level3))
                reason += " > " + downtime.Level3;

            string comment = DCSDashboardDemoHelper.GetRandomComment(reason);

            int reasonId = downtime.ID;

            */

            bool result = false;
            using (DB db = new DB())
            {
                DowntimeData dd = new DowntimeData();
                dd.EventStart = startdatetime;
                dd.EventStop = enddatetime;
                dd.Minutes = minutes;
                dd.Line = line;
                dd.Client = "admin";
                db.AddToDowntimeDataSet(dd);

                result = db.SaveChanges() > 0;
            }

              //      stopEventLine();

            return result.ToString();
        }
开发者ID:bsimp6983,项目名称:BackupDashes,代码行数:50,代码来源:TvDemoControl.aspx.cs

示例6: UpdateCC


//.........这里部分代码省略.........
                    {
                        for (int x = 0; x < diff; x++)
                        {
                            if (date.Value.Hour == end.Hour)
                                break;

                            total += val;
                            counter += val;

                            CaseCount cc = new CaseCount();
                            cc.CaseCount1 = Convert.ToInt32(total);
                            cc.Client = "lebelge";
                            cc.EventStart = date;
                            cc.EventStop = date;
                            cc.Line = "company-demo";

                            tmpList.Add(cc);

                            date = date.Value.AddMinutes(5d);

                        }
                    }

                    if (tmpList.Count > 0)
                    {
                        tmpList.ElementAt(tmpList.Count - 1).CaseCount1 = tmpList.ElementAt(0).CaseCount1 + casecount;

                        foreach (CaseCount cc in tmpList)
                        {
                            db.AddToCaseCountSet(cc);
                        }
                    }

                    if (db.SaveChanges() >= 0)
                        return "Success" + d.ToString("MM/dd/yyyy hh:mm:ss tt");
                    else
                        return "ERROR";

                }

            }

            return "ERROR";

        }
        */
        protected string UpdateCC()
        {
            int casecount = -1;

            DateTime d;
            DateTime? date = null;

            if (DateTime.TryParse(Request.Form["date"], out d))
                date = new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, 00);

            int.TryParse(Request.Form["counts"], out casecount);

            if (casecount > -1 && date.HasValue)
            {

                using (DB db = new DB())
                {
                    List<ThroughputHistory> thList = DCSDashboardDemoHelper.getThroughPutHistories("company-demo");

                    ThroughputHistory th = (from o in thList
开发者ID:bsimp6983,项目名称:BackupDashes,代码行数:67,代码来源:ManualCC.aspx.cs

示例7: GetAscommStatus

        public static AscommStatus GetAscommStatus(string client, string line)
        {
            using (DB db = new DB(GetConnectionString()))
            {
                AscommStatus status =  (from o in db.AscommStatuses
                                        where o.Client == client
                                        && o.Line == line
                                    select o).FirstOrDefault();

                if (status == null)
                {
                    status = new AscommStatus();
                    status.Client = Filter_Client;
                    status.LastPing = DateTime.Now;
                    status.Line = line;
                    status.Status = false;

                    db.AddToAscommStatuses(status);

                    db.SaveChanges();
                }

                return status;
            }
        }
开发者ID:bsimp6983,项目名称:BackupDashes,代码行数:25,代码来源:DBHelper.cs

示例8: UpdateAscommPing

        public static void UpdateAscommPing(string client, DateTime date, string line, bool s)
        {
            using (DB db = new DB(GetConnectionString()))
            {
                AscommStatus status = (from o in db.AscommStatuses
                                       where o.Client == client
                                       && o.Line == line
                                       select o).FirstOrDefault();

                if (status == null)
                {
                    status = new AscommStatus();

                    status.Client = client;
                    status.LastPing = DateTime.Now;
                    status.Status = s;
                    status.Line = line;

                    db.AddToAscommStatuses(status);
                }
                else
                {
                    status.Status = s;
                    status.LastPing = date;
                }

                db.SaveChanges();
            }
        }
开发者ID:bsimp6983,项目名称:BackupDashes,代码行数:29,代码来源:DBHelper.cs


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