public bool Save(ModuleAccessCtrlTransaction module, string state = "") { try { if (!string.IsNullOrEmpty(state) && state == "Save") { moduleAccessCtrlTransactionRepository.Add(module); } else if (!string.IsNullOrEmpty(state) && state == "Update") { moduleAccessCtrlTransactionRepository.Update(module); } } catch (DbEntityValidationException e) { string exceptionMessage = string.Empty; foreach (var eve in e.EntityValidationErrors) { exceptionMessage = string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { exceptionMessage += string.Format("\n\n- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw new Exception(exceptionMessage); } catch (Exception ex) { throw new Exception(ex.Message); } return(true); }
public void Update(ModuleAccessCtrlTransaction txn) { using (var context = new InventoryContext()) { context.Entry(txn).State = EntityState.Modified; context.SaveChanges(); } }
public void Add(ModuleAccessCtrlTransaction txn) { using (var context = new InventoryContext()) { var searchModuleAccessCtrlTransaction = context.ModuleAccessCtrlTransactions.Where(x => x.RoleID == txn.RoleID && x.ModuleID == txn.ModuleID).FirstOrDefault(); if (searchModuleAccessCtrlTransaction == null) { context.ModuleAccessCtrlTransactions.Add(txn); context.SaveChanges(); } } }