public ActionResult Edit(FormCollection formCollection, StorePromotionViewModel vo) { if (!ModelState.IsValid) { return(View(vo)); } var entity = _storepromotionRepo.Find(vo.Id); entity.Name = vo.Name; entity.Description = vo.Description; entity.CouponStartDate = vo.CouponStartDate; entity.CouponEndDate = vo.CouponEndDate; entity.MinPoints = vo.MinPoints; entity.UnitPerPoints = vo.UnitPerPoints; entity.Notice = vo.Notice; entity.Status = vo.Status; entity.UsageNotice = vo.UsageNotice; entity.InScopeNotice = vo.ComposedScopeNotice; entity.PromotionType = vo.PromotionType; entity.AcceptPointType = vo.AcceptPointType; entity.ActiveStartDate = vo.ActiveStartDate; entity.ActiveEndDate = vo.ActiveEndDate; entity.UpdateDate = DateTime.Now; entity.UpdateUser = base.CurrentUser.CustomerId; var scopeEntities = vo.Scope.Where(s => s.Status != (int)DataStatus.Deleted) .Select(s => s.ToEntity <StorePromotionScopeEntity>(se => { se.Status = (int)DataStatus.Normal; se.UpdateUser = CurrentUser.CustomerId; se.UpdateDate = DateTime.Now; se.CreateDate = DateTime.Now; se.CreateUser = CurrentUser.CustomerId; })); var rulEntities = vo.Rules.Where(s => s.Status != (int)DataStatus.Deleted) .Select(s => s.ToEntity <PointOrderRuleEntity>(sp => { sp.Status = (int)DataStatus.Normal; sp.UpdateUser = CurrentUser.CustomerId; sp.UpdateDate = DateTime.Now; sp.CreateDate = DateTime.Now; sp.CreateUser = CurrentUser.CustomerId; })); using (var ts = new TransactionScope()) { _storepromotionRepo.Update(entity); var oldScopes = _scopeRepo.Get(s => s.StorePromotionId == entity.Id && s.Status != (int)DataStatus.Deleted); foreach (var oscope in oldScopes) { _scopeRepo.Delete(oscope); } foreach (var scopeE in scopeEntities) { scopeE.StorePromotionId = entity.Id; _scopeRepo.Insert(scopeE); } var oldRules = this._ruleRepo.Get(s => s.StorePromotionId == entity.Id && s.Status != (int)DataStatus.Deleted); foreach (var orule in oldRules) { _ruleRepo.Delete(orule); } foreach (var ruleE in rulEntities) { ruleE.StorePromotionId = entity.Id; _ruleRepo.Insert(ruleE); } ts.Complete(); } return(RedirectToAction("detail", new { id = entity.Id })); }