public ActionResult Edit(TargetOfMonthForMember item) { this.AddErrorStateIfTargetOfMonthNoValid(item); if (ModelState.IsValid) { //this.AddErrorStateIfTargetOfMonthNoValid(item); CH.DB.SaveChanges(); CH.DB.ChangeTracker.DetectChanges(); var list = CH.DB.ChangeTracker.Entries <TargetOfMonthForMember>().ToList(); if (list.Count > 0) { var attacth = list.First().Entity; CH.DB.Detach(attacth); } list = CH.DB.ChangeTracker.Entries <TargetOfMonthForMember>().ToList(); CH.Edit <TargetOfMonthForMember>(item); return(RedirectToAction("MyTargetIndex", new { projectid = item.ProjectID })); } ViewBag.ProjectID = item.ProjectID; return(View(item)); }
public ActionResult Create(TargetOfMonthForMember item) { this.AddErrorStateIfTargetOfMonthNoValid(item); if (ModelState.IsValid) { CH.Create <TargetOfMonthForMember>(item); return(RedirectToAction("MyTargetIndex", new { projectid = item.ProjectID })); } ViewBag.ProjectID = item.ProjectID; return(View(item)); }
public static void AddErrorStateIfTargetOfMonthNoValid(this Controller item, TargetOfMonthForMember t) { item.AddErrorStateIfStartDateLaterThanEndDate(t.StartDate, t.EndDate); if (t.StartDate.StartOfMonth() != t.StartDate) { item.ModelState.AddModelError("", "开始时间必须是每个月的一号"); } if (t.EndDate.EndOfMonth() != t.EndDate) { item.ModelState.AddModelError("", "结束时间必须是每个月的最后一天"); } //if (t.BaseDeal > t.Deal) // item.ModelState.AddModelError("", "保底目标不能大于Deal"); if (t.Deal <= 0 || t.CheckIn <= 0) { item.ModelState.AddModelError("", "出单目标和入账目标必须大于0"); } if (t.StartDate.Month != t.EndDate.Month) { item.ModelState.AddModelError("", "开始时间和结束时间不在同一个月内"); } var ts = from et in CH.DB.TargetOfMonthForMembers where et.StartDate == t.StartDate && t.ProjectID == et.ProjectID && et.ID != t.ID && et.MemberID == t.MemberID select et; if (ts.Count() > 0) { item.ModelState.AddModelError("", "该月的目标已经添加,不能再次添加"); } if ((t.TargetOf1stWeek + t.TargetOf2ndWeek + t.TargetOf3rdWeek + t.TargetOf4thWeek + t.TargetOf5thWeek) < t.Deal) { item.ModelState.AddModelError("", "周出单目标总和必须大于等于月销售目标"); } if ((t.CheckInOf1stWeek + t.CheckInOf2ndWeek + t.CheckInOf3rdWeek + t.CheckInOf4thWeek + t.CheckInOf5thWeek) < t.CheckIn) { item.ModelState.AddModelError("", "入账周目标划分总额要大于等于月入账目标划分总额"); } }