Example #1
0
        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);
        }
Example #2
0
 public void Update(ModuleAccessCtrlTransaction txn)
 {
     using (var context = new InventoryContext())
     {
         context.Entry(txn).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #3
0
 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();
         }
     }
 }