public ActionResult Create(FormCollection formCollection, StorePromotionViewModel vo) { if (!ModelState.IsValid) { return(View(vo)); } var entity = vo.ToEntity <StorePromotionEntity>(); entity.CreateDate = DateTime.Now; entity.CreateUser = base.CurrentUser.CustomerId; entity.UpdateDate = DateTime.Now; entity.UpdateUser = base.CurrentUser.CustomerId; entity.Status = (int)DataStatus.Default; entity.InScopeNotice = vo.ComposedScopeNotice; 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()) { entity = _storepromotionRepo.Insert(entity); foreach (var scopeE in scopeEntities) { scopeE.StorePromotionId = entity.Id; _scopeRepo.Insert(scopeE); } foreach (var ruleE in rulEntities) { ruleE.StorePromotionId = entity.Id; _ruleRepo.Insert(ruleE); } ts.Complete(); } return(RedirectToAction("Edit", new { id = entity.Id })); }