Beispiel #1
0
        public string create(AccountGroup item)
        {
            var result = AccountGroupDbContext.getInstance().findGroupsByNameNoTracking(item.Name);

            if (result != null && result.Count > 0)
            {
                return("This Account Group Name already exists. Please enter another Account Group Name.");
            }

            using (var db = new BaseDbContext())
            {
                db.accountGroupDb.Add(item);
                db.SaveChanges();
                return(null);
            }
        }
Beispiel #2
0
        public string edit(AccountGroup item)
        {
            var accountGroup = findGroupByID(item.AccountGroupID);

            var result = AccountGroupDbContext.getInstance().findGroupsByNameNoTracking(item.Name);

            if (result != null && result.Count > 0)
            {
                foreach (var res in result)
                {
                    if (item.AccountGroupID != res.AccountGroupID)
                    {
                        return("This Account Group Name already exists. Please enter another Account Group Name.");
                    }
                }
            }

            item.AccessibleCategories         = String.Join(",", item.getAccessibleCategoryList().ToArray());
            accountGroup.AccessibleCategories = item.AccessibleCategories;

            using (var db = new BaseDbContext())
            {
                var local = db.accountGroupDb
                            .Local
                            .FirstOrDefault(f => f.AccountGroupID == item.AccountGroupID);
                if (local != null)
                {
                    db.Entry(local).State = EntityState.Detached;
                }

                db.Entry(accountGroup).State = EntityState.Modified;

                db.SaveChanges();
                return(null);
            }
        }