public bool Add(string code, string name, string type)
 {
     try
     {
         if (db.Repository <ICD10>().ReadAll().Any(a => a.ICD10Code == code))
         {
             ValidationDictionary.AddGeneralError("Duplicated");
             return(false);
         }
         db.Repository <ICD10>().Create(new ICD10
         {
             ICD10Code = code,
             StdName   = name,
             Type      = type
         });
         Save();
         return(true);
     }
     catch (Exception ex)
     {
         ValidationDictionary.AddPropertyError <ICD10ViewModel>(
             i => i.ICD10Code, ex.Message);
         return(false);
     }
 }
 public void Edit(AccountEditView model)
 {
     try
     {
         var account = Read(a => a.ID == model.ID);
         if (!account.HasValue())
         {
             ValidationDictionary.AddPropertyError <Account>(a => a.ID, "ID not found.");
             return;
         }
         if (ReadAll()
             .Any(x => (x.Email.Equals(model.Email, StringComparison.InvariantCultureIgnoreCase) ||
                        x.UserNo.Equals(model.UserNo, StringComparison.InvariantCultureIgnoreCase)
                        ) && x.ID != model.ID))
         {
             ValidationDictionary.AddPropertyError <AccountEditView>(a => a.Email, "Email Duplicated.");   //.AddGeneralError("Email Duplicated");
         }
         else
         {
             model.MapTo(account);
             db.Repository <Account2Dept>().Delete(a => a.AccountId == model.ID);
             Array.ForEach(
                 model.DepartmentIDs.OrEmptyIfNull().Concat(model.BureauDepartmentIDs.OrEmptyIfNull()).ToArray()
                 , a => account.Account2Dept.Add(new Account2Dept(a)));
             db.Repository <Account2Role>().Delete(a => a.Account_id == model.ID);
             Array.ForEach(model.RoleIDs.OrEmptyIfNull().ToArray()
                           , a => account.Account2Role.Add(new Account2Role(a)));
             Save();
         }
     }
     catch (Exception ex)
     {
         ValidationDictionary.AddGeneralError(ex.Message);
     }
 }
 public void Create(AccountCreateView model)
 {
     try
     {
         model.Email = model.Email + Config.AppSetting("EmailDomain");
         if (db.Repository <Account>().ReadAll()
             .Any(x => x.Email.Equals(model.Email, StringComparison.InvariantCultureIgnoreCase) ||
                  x.UserNo.Equals(model.UserNo, StringComparison.InvariantCultureIgnoreCase)))
         {
             ValidationDictionary.AddPropertyError <AccountCreateView>(a => a.Email, "Email Duplicated.");
         }
         else
         {
             model.MapTo(out Account account);
             account.Password = Config.Md5Salt(model.Password);
             Array.ForEach(
                 model.DepartmentIDs.OrEmptyIfNull().Concat(model.BureauDepartmentIDs.OrEmptyIfNull()).ToArray()
                 , a => account.Account2Dept.Add(new Account2Dept(a)));
             Array.ForEach(model.RoleIDs.OrEmptyIfNull().ToArray()
                           , a => account.Account2Role.Add(new Account2Role(a)));
             Create(account);
             Save();
         }
     }
     catch (Exception ex)
     {
         ValidationDictionary.AddGeneralError(ex.Message);
     }
 }
 public bool Edit(string code, string name, string type)
 {
     try
     {
         var update = db.Repository <ICD10>().Read(o => o.ICD10Code == code);
         update.StdName = name;
         update.Type    = type;
         Save();
         return(true);
     }
     catch (Exception ex)
     {
         ValidationDictionary.AddPropertyError <ICD10ViewModel>(
             i => i.ICD10Code, ex.Message);
         return(false);
     }
 }
Beispiel #5
0
        public bool SetGeneralSetting(SettingView viewModel)
        {
            DefaultSettings generalSettings = new DefaultSettings();

            var config = new MapperConfiguration(cfg => cfg.CreateMap <SystemSettingView, DefaultSettings>());
            var mapper = config.CreateMapper();

            generalSettings = mapper.Map <DefaultSettings>(viewModel.SystemSettingView);

            if (!TestTimeValid(viewModel.SystemSettingView.Opd_Shift_Morning_Start))
            {
                ValidationDictionary.AddPropertyError <SettingView>(
                    s => s.SystemSettingView.Opd_Shift_Morning_Start, "Wrong Format");
            }
            if (!TestTimeValid(viewModel.SystemSettingView.Opd_Shift_Morning_End))
            {
                ValidationDictionary.AddPropertyError <SettingView>(
                    s => s.SystemSettingView.Opd_Shift_Morning_End, "Wrong Format");
            }
            if (!TestTimeValid(viewModel.SystemSettingView.Opd_Shift_Afternoon_Start))
            {
                ValidationDictionary.AddPropertyError <SettingView>(
                    s => s.SystemSettingView.Opd_Shift_Afternoon_Start, "Wrong Format");
            }
            if (!TestTimeValid(viewModel.SystemSettingView.Opd_Shift_Afternoon_End))
            {
                ValidationDictionary.AddPropertyError <SettingView>(
                    s => s.SystemSettingView.Opd_Shift_Afternoon_End, "Wrong Format");
            }
            if (!TestTimeValid(viewModel.SystemSettingView.Opd_Shift_Night_Start))
            {
                ValidationDictionary.AddPropertyError <SettingView>(
                    s => s.SystemSettingView.Opd_Shift_Night_Start, "Wrong Format");
            }
            if (!TestTimeValid(viewModel.SystemSettingView.Opd_Shift_Night_End))
            {
                ValidationDictionary.AddPropertyError <SettingView>(
                    s => s.SystemSettingView.Opd_Shift_Night_End, "Wrong Format");
            }
            if (viewModel.SystemSettingView.BK_img_file != null)
            {
                var s = MobileHis.Misc.Storage.GetStorage(StorageScope.backgroundImg);
                generalSettings.BK_img = s.Write(
                    viewModel.SystemSettingView.BK_img_file.FileName, viewModel.SystemSettingView.BK_img_file);
            }
            if (viewModel.SystemSettingView.Official_Banner_Img_file != null)
            {
                var s = MobileHis.Misc.Storage.GetStorage(StorageScope.Official);
                generalSettings.Official_Banner_Img = s.Write(
                    viewModel.SystemSettingView.Official_Banner_Img_file.FileName,
                    viewModel.SystemSettingView.Official_Banner_Img_file);
            }
            if (viewModel.SystemSettingView.Official_Logo_Img_file != null)
            {
                var s = MobileHis.Misc.Storage.GetStorage(StorageScope.Official);
                generalSettings.Official_Logo_Img = s.Write(
                    viewModel.SystemSettingView.Official_Logo_Img_file.FileName,
                    viewModel.SystemSettingView.Official_Logo_Img_file);
            }
            if (viewModel.SystemSettingView.PartnerFile != null)
            {
                var settings     = db.Repository <Setting>().ReadAll().Include(a => a.ParentSetting);
                var partnerImage = settings.Where(a => a.SettingName.Contains("Partner") &&
                                                  a.ParentSetting.SettingName == SettingTypes.Default.ToString() &&
                                                  string.IsNullOrEmpty(a.Value))
                                   .OrderBy(a => a.SettingName).ToList();
                var cnt = 0;
                foreach (var file in viewModel.SystemSettingView.PartnerFile)
                {
                    if (file != null)
                    {
                        var fileName = new System.IO.FileInfo(file.FileName).Name;
                        var s        = MobileHis.Misc.Storage.GetStorage(StorageScope.Official);
                        fileName = s.Write(fileName, file);
                        partnerImage[cnt].Value = fileName;
                        //settingDAL.Edit(partnerImage[cnt]);
                        cnt++;
                    }
                }
            }
            if (!ValidationDictionary.IsValid())
            {
                return(false);
            }
            SetGroupSetting(SettingTypes.Default, generalSettings);
            Save();
            return(true);
        }