示例#1
0
        public static AppSystem Update(AppSystem appSystem)
        {
            using (var dbContext = new SqlExpIdentity())
            {
                try
                {
                    AppSystem tmpSystem = dbContext.appSystems.Where(w => w.Id == appSystem.Id).FirstOrDefault();
                    if (tmpSystem == null)
                    {
                        tmpSystem = new AppBuilder().AppName(appSystem.Name).AppDesc(appSystem.Desc).Build();
                        tmpSystem = Create(tmpSystem);
                    }
                    else
                    {
                        tmpSystem.Name       = appSystem.Name != appSystem.Name ? tmpSystem.Name : appSystem.Name;
                        tmpSystem.Desc       = appSystem.Desc != appSystem.Desc ? tmpSystem.Desc : appSystem.Desc;
                        tmpSystem.UpdateDate = DateTime.Now;
                        int updCount = dbContext.SaveChanges();
                    }

                    return(tmpSystem);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
示例#2
0
        public IEnumerable <UserDetailJson> LoadUsers()
        {
            string jsonDataDir             = CommonFileProcs.GetLocalDirectory("JsonData");
            string jsonData                = CommonFileProcs.GetAllRecords(jsonDataDir, "UserAccountInitList.json");
            List <UserDetailJson> rtn_list = CommonJSONProcs.ProcessJSONClass <UserDetailJson>(jsonData);

            using (var db_con = new SqlExpIdentity())
            {
                var users = db_con.Users.ToList();
                foreach (UserDetailJson json_user in rtn_list)
                {
                    AspNetUser ident_user = new AspNetUser(json_user);
                    db_con.Users.Add(ident_user);
                }
                try
                {
                    int row_cnt = db_con.SaveChanges();
                }
                catch
                {
                    var errors    = db_con.GetValidationErrors();
                    var errorList = CommonErrorProcs.ExtractValidationErrors(db_con);
                    //return errorList;
                }
            }

            return(rtn_list);
        }
示例#3
0
 public static AppSystem Create(AppSystem appSystem)
 {
     using (var dbContext = new SqlExpIdentity())
     {
         try
         {
             appSystem.CreateDate = DateTime.Now;
             appSystem.UpdateDate = DateTime.Now;
             dbContext.appSystems.Add(appSystem);
             dbContext.SaveChanges();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     return(appSystem);
 }
示例#4
0
 public static AppSystem Delete(AppSystem appSystem)
 {
     using (var dbContext = new SqlExpIdentity())
     {
         try
         {
             AppSystem tmpSystem = dbContext.appSystems.Where(w => w.Id == appSystem.Id).FirstOrDefault();
             if (tmpSystem != null)
             {
                 dbContext.appSystems.Remove(tmpSystem);
                 dbContext.SaveChanges();
             }
             return(tmpSystem);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
示例#5
0
 public static AppRole AddRole(string appName, AppRole appRole)
 {
     using (var dbContext = new SqlExpIdentity())
     {
         try
         {
             AppSystem appSystem = dbContext.appSystems.Where(w => w.Name == appName).FirstOrDefault();
             if (appSystem == null)
             {
                 throw new ArgumentNullException("AppName");
             }
             appSystem.AppRoles.Add(appRole);
             dbContext.SaveChanges();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     return(appRole);
 }