public void Update(RoleModulesHeader Header, List <RoleModulesLine> LineItems) { _dbContext.Entry(Header).State = EntityState.Modified; foreach (var item in LineItems) { _dbContext.Entry(item).State = EntityState.Modified; } _dbContext.SaveChanges(); }
public void Add(RoleModulesHeader Header, List <RoleModulesLine> LineItems) { _dbContext.RoleModulesHeader.Add(Header); foreach (var item in LineItems) { item.RoleModulesHeader = Header; _dbContext.RoleModulesLine.Add(item); } _dbContext.SaveChanges(); }
public IActionResult Save(RoleModuleAssignmentViewModel model) { if (ModelState.IsValid) { var header = new RoleModulesHeader { Id = model.Header.Id, Role = _RoleModule.GetRoleById(int.Parse(model.Header.RoleId)) }; var lineitems = new List <RoleModulesLine>(); foreach (var item in model.LineItems) { var line = new RoleModulesLine { Id = item.Id, Approve = item.Approve, Delete = item.Delete, Export = item.Export, Import = item.Import, New = item.New, Print = item.Print, Post = item.Post, Save = item.Save, Search = item.Search, Module = _RoleModule.GetModuleById(int.Parse(item.Module)) }; lineitems.Add(line); } if (header.Id.ToString().Length <= 0) { _RoleModule.Add(header, lineitems); } else { _RoleModule.Update(header, lineitems); } } return(View()); }