public void Create(CodeFileViewModel model) { try { var codeFile = Read(x => x.ItemType.Equals(model.ItemType) && x.ItemCode.Equals(model.ItemCode)); if (codeFile != null) { if (!IsDeleted(codeFile)) { ValidationDictionary.AddGeneralError(@LocalRes.Resource.MSG_Duplidate); } else { codeFile.ParentCodeFile = model.ParentCodeFile; codeFile.CheckFlag = ""; //codeFile.ModUser = model.ModUser; } } else { codeFile = ToCreateEntity(model); Create(codeFile); } Save(); } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
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 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 void Create(RoomModel model) { try { var item = Read(a => a.RoomNo.Equals( model.RoomNo, StringComparison.CurrentCultureIgnoreCase)); if (item != null) { DuplicatedError(); } else { //item =_mapper.Map<Room>(model); item = ToCreateEntity(model); item.RoomNo = model.RoomNo; Create(item); if (!model.AllowDept.IsNullOrEmpty()) { CreateByText(model.AllowDept, item.ID); } Save(); } } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void ChangePassword(ChangePasswordView model) { try { string md5SaltPassword = Config.Md5Salt(model.Password); var account = Read(x => x.Email.Equals(_principal.Email, StringComparison.InvariantCultureIgnoreCase) && x.Password == md5SaltPassword); //判斷是否存在 if (account == null) { ValidationDictionary.AddGeneralError("Account ID or password error"); } else { account.Password = Config.Md5Salt(model.newPassword); account.ModDate = System.DateTime.Now; Save(); } } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
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 Update(RoomModel model) { try { var item = Read(a => a.ID == model.ID); if (item != null) { //item = _mapper.Map(model, item); ToUpdateEntity(model, item); var dept2Room = db.Repository <Dept2Room>().ReadAll().Where(a => a.Room_id == model.ID).ToList(); if (dept2Room != null) { db.Repository <Dept2Room>().Delete(dept2Room); } if (!model.AllowDept.IsNullOrEmpty()) { CreateByText(model.AllowDept, model.ID); } } Save(); } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Delete(int ID) { try { var rooms = db.Repository <Room>().ReadAll(); var relatedRooms = rooms.Where(a => a.Guardian_ID == ID); foreach (var room in relatedRooms) { room.Guardian_ID = null; } var educationFiles = db.Repository <HealthEdu_File>().ReadAll(); var relatedFiles = educationFiles.Where(a => a.HealthEdu_ID == ID); foreach (var file in relatedFiles) { var s = Storage.GetStorage(StorageScope.GuardianUpload); s.Delete(file.FileName, file.HealthEdu_ID); db.Repository <HealthEdu_File>().Delete(file); } var education = db.Repository <HealthEdu>().Read(a => a.ID == ID); db.Repository <HealthEdu>().Delete(education); Save(); } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void DeleteIMG(int ID) { try { var file = db.Repository <HealthEdu_File>().Read(a => a.ID == ID); var files = file.Guardian.HealthEdu_File .Where(a => a.ID != file.ID) .OrderByDescending(a => a.IsUsed) .ThenBy(a => a.Show_Order).ToList(); db.Repository <HealthEdu_File>().Delete(file); for (int i = 0; i < files.Count; i++) { var g = files[i]; g.Show_Order = i + 1; } var s = Storage.GetStorage(StorageScope.GuardianUpload); s.Delete(file.FileName, file.HealthEdu_ID); Save(); } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Create(EducationModel model) { try { var education = ToCreateEntity(model); Create(education); Save(); } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Create(VendorModel model) { try { //model.CodeFileSelectListEvent += _codeFileService.GetDropDownList; //var vendor = _modelMapper.Map<Vendor>(model); var vendor = ToCreateEntity(model); Create(vendor); Save(); }catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Delete(int ID) { try { var account = Read(a => a.ID == ID); if (account != null) { Delete(account); Save(); } } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Delete(int ID) { try { var codeFile = Read(a => a.ID == ID); if (codeFile != null) { codeFile.CheckFlag = "D"; Save(); } } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Update(CodeFileViewModel model) { try { var codeFile = Read(a => a.ID == model.ID); if (codeFile != null) { ToUpdateEntity(model, codeFile); Save(); } } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Create(string roleName) { try { if (ReadAll().Any(a => a.name == roleName)) { ValidationDictionary.AddGeneralError("Duplicated"); return; } Create(new Role(roleName)); Save(); } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Delete(int ID) { try { var dept2Room = db.Repository <Dept2Room>().ReadAll().Where(a => a.Room_id == ID).ToList(); if (dept2Room != null) { db.Repository <Dept2Room>().Delete(dept2Room); } var room = db.Repository <Room>().Read(a => a.ID == ID); db.Repository <Room>().Delete(room); Save(); }catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Delete(int ID) { try { var department = Read(a => a.ID == ID); if (department != null) { Delete(department); } else { ValidationDictionary.AddGeneralError(LocalRes.Resource.MSG_Duplidate); } Save(); } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Create(DepartmentIndexModel model) { try { var department = Read(a => a.DepNo.Equals(model.DepNo, StringComparison.CurrentCultureIgnoreCase)); if (department != null) { ValidationDictionary.AddGeneralError(@LocalRes.Resource.MSG_Duplidate); } else { department = ToCreateEntity(model); Create(department); Save(); } }catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Update(DrugVendorModel model) { try { var drugVendor = IDService.Read(model.ID); if (drugVendor == null) { NotFoundError(); } else { ToUpdateEntity(model, drugVendor); Save(); } } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void ResetPassword(int id) { try { var account = Read(a => a.ID == id); if (account == null) { ValidationDictionary.AddGeneralError("Account ID error"); } else { account.Password = Config.Md5Salt("12345"); Save(); } } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Update(DepartmentIndexModel model) { try { var department = Read(a => a.ID == model.ID); if (department != null) { department.DepName = model.DepName; department.IsRegistered = model.IsRegistered; department.UnitId = model.UnitId; Save(); } else { ValidationDictionary.AddGeneralError(LocalRes.Resource.MSG_Duplidate); } }catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Create(DrugVendorModel model) { try { var existDrugVendor = db.Repository <DrugVendor>().ReadAll() .Where(a => model.DrugGuidList.Any(d => d == a.DrugGID)) .ToList(); existDrugVendor.ForEach(m => { m.IsDeleted = false; m.Creator = 0; }); List <DrugVendor> drugVendors = model.DrugGuidList .Where(b => !existDrugVendor.Select(a => a.DrugGID).Any(guid => guid == b)) .Select(a => new DrugVendor(drugGuid: a, vendorID: model.ID)).ToList(); Create(drugVendors); Save(); } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Update(VendorModel model) { //model.CodeFileSelectListEvent += _codeFileService.GetDropDownList; var vendor = Read(a => a.ID == model.ID); try { if (vendor != null) { //vendor = _modelMapper.Map(model, vendor); ToUpdateEntity(model, vendor); Save(); } else { NotFoundError(); } }catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Edit(EducationModel model) { try { //model.CodeFileSelectListEvent += _codeFileService.GetDropDownList; var education = db.Repository <HealthEdu>().Read(a => a.ID == model.ID); if (education != null) { var storageAttach = Storage.GetStorage(StorageScope.GuardianUpload); var educationFiles = db.Repository <HealthEdu_File>().ReadAll().Where(a => a.HealthEdu_ID == model.ID); int showOrder = (educationFiles.Count() > 0) ? educationFiles.Max(a => a.Show_Order) + 1 : 1; int defaultShowSeconds = 5; foreach (var file in model.UploadFiles.OrEmptyIfNull()) { if (file != null && !file.FileName.IsNullOrEmpty()) { var fileName = new System.IO.FileInfo(file.FileName).Name; if (!storageAttach.FileExist(fileName, model.ID) && storageAttach.CheckExtensions(System.IO.Path.GetExtension(fileName))) { fileName = storageAttach.Write(fileName, file, model.ID); var newFile = new HealthEdu_File { HealthEdu_ID = model.ID, FileName = fileName, Show_Order = showOrder, Show_Seconds = defaultShowSeconds, IsUsed = true }; db.Repository <HealthEdu_File>().Create(newFile); showOrder++; } } } foreach (var file in model.EducationFiles.OrEmptyIfNull()) { var updatedFile = db.Repository <HealthEdu_File>().Read(a => a.ID == file.ID && a.HealthEdu_ID == file.HealthEdu_ID); updatedFile.Show_Seconds = file.Show_Seconds; updatedFile.IsUsed = file.IsUsed; updatedFile.Show_Order = file.Show_Order; } education.HealthEdu_Type_CodeFile = model.HealthEdu_Type_CodeFile; education.HealthEdu_Name = model.HealthEdu_Name; education.IsUsed = model.IsUsed; education.IsForLobbyUsed = model.IsForLobbyUsed; education.QueueMsg = model.QueueMsg; Save(); } } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void CreateOrUpdate(DrugViewModel viewModel) { bool isNewDrug = viewModel.GID == null; Drug drug = isNewDrug ? new Drug { GID = Guid.NewGuid() } : db.Repository <Drug>().Read(a => a.GID == viewModel.GID); var config = new MapperConfiguration(cfg => cfg.CreateMap <DrugViewModel, Drug>()); var mapper = config.CreateMapper(); mapper.Map(viewModel, drug); if (viewModel.IsDefaultType) { drug.PatientFromType = viewModel.PatientFrom; } try { if (isNewDrug) { db.Repository <Drug>().Create(drug); } if (viewModel.HasAppearance) { bool isNewAppearance = false; DrugAppearance drugAppearance = db.Repository <DrugAppearance>().Read(a => a.DrugID == drug.GID); if (drugAppearance == null) { drugAppearance = new DrugAppearance(drug.GID); isNewAppearance = true; } drugAppearance.Color = viewModel.Color; drugAppearance.MajorType = viewModel.MajorType; drugAppearance.Shape = viewModel.Shape; if (isNewAppearance) { db.Repository <DrugAppearance>().Create(drugAppearance); } } bool isNewCost = false; DrugCost drugCost = db.Repository <DrugCost>().Read(a => a.DrugID == drug.GID); if (drugCost == null) { drugCost = drugCost ?? new DrugCost(drug.GID); isNewCost = true; } if (viewModel.IsDefaultType) { viewModel.Price = 0; drugCost.InitialFee = viewModel.InitialFee; drugCost.DailyFee = viewModel.DailyFee; } drugCost.Price = viewModel.Price; if (isNewCost) { db.Repository <DrugCost>().Create(drugCost); } else { db.Repository <DrugCost>().Update(drugCost); } if (viewModel.Photo != null) { var storage = MobileHis.Misc.Storage.GetStorage(StorageScope.Drug); storage.Write(drug.GID, viewModel.Photo); } db.Save(); }catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }