public AppAssigneeDetailDTO Edit(AppAssigneeDetailDTO model) { if (model.AppType == "TRL") { if (model.OrgPositionType == "Manager") { model.ListOfBranches = null; } else { model.BranchId = Guid.Empty; } } model.Id = DataService.Add <AppAssignee>(model); DataService.SaveChanges(); var assigneeBranches = DataService.GetEntity <AppAssigneeBranch>(x => x.AssigneeId == model.Id); foreach (var x in assigneeBranches) { DataService.Remove(x); } if (model.AppType == "TRL") { if (model.OrgPositionType == "Manager") { DataService.Add(new AppAssigneeBranch { AssigneeId = model.Id, BranchId = model.BranchId.Value }); } else { model.ListOfBranches?.ForEach(branchId => DataService.Add(new AppAssigneeBranch { AssigneeId = model.Id, BranchId = branchId })); } } else { model.ListOfBranches?.ForEach(branchId => DataService.Add(new AppAssigneeBranch { AssigneeId = model.Id, BranchId = branchId })); } DataService.SaveChanges(); return(model); }
public ValidateResult Delete(Guid id) { var entity = _dataService.GetById <TEntity>(id); if (entity == null) { return(new ValidateResult("Запись не найдена", id.ToString())); } _dataService.Remove(entity); _dataService.SaveChanges(); return(new ValidateResult(null, id.ToString())); }
public void SaveDecision(AppDecisionDTO model) { var decision = _dataService.GetEntity <AppDecision>(p => p.Id == model.Id).SingleOrDefault(); var isUpdate = false; if (decision == null) { decision = new AppDecision(); } else { _dataService.GetEntity <AppDecisionReason>(p => p.AppDecisionId == decision.Id).ToList() .ForEach(x => _dataService.Remove(x)); isUpdate = true; } _objectMapper.Map(model, decision); foreach (var reason in model.ListOfDecisionReason) { decision.AppDecisionReasons.Add(new AppDecisionReason { ReasonType = reason, AppDecisionId = decision.Id }); } var trl = _dataService.GetEntity <TrlApplication>(p => p.Id == decision.AppId).SingleOrDefault(); if (trl == null || string.IsNullOrEmpty(trl.ExpertiseResult) || trl.AppState == "Reviewed") { return; } trl.AppDecision = decision; _dataService.Add(decision, isUpdate); _limsExchangeService.ExportDecisionTRL(decision, isUpdate); // TODO: Сделать _dataService.SaveChanges(); }
public async Task <Guid> Save(BranchDetailsDTO model) { var check = model.Id == Guid.Empty; if (check) { model.IsFromLicense = false; } var branchId = _dataService.Add <Branch>(model); await _dataService.SaveChangesAsync(); if (check) { var applicationBranch = new ApplicationBranch { LimsDocumentId = model.ApplicationId, BranchId = branchId }; _dataService.Add(applicationBranch); await _dataService.SaveChangesAsync(); if (model.AppType == "TRL") { //Вид діяльності обраний в МПД var trlActivityTypeEnum = _dataService.GetEntity <EnumRecord>(x => x.Code == model.TrlActivityType)?.FirstOrDefault(); _dataService.Add(new EntityEnumRecords() { EntityId = branchId, EntityType = "BranchApplication", EnumRecordType = trlActivityTypeEnum?.EnumType, EnumRecordCode = trlActivityTypeEnum?.Code }); if (model.PharmacyId != null) { _dataService.Add(new PharmacyItemPharmacy() { PharmacyId = model.PharmacyId.Value, PharmacyItemId = branchId }); } await _dataService.SaveChangesAsync(); } } else { if (model.AppType == "TRL") { var pharmacyItem = _dataService.GetEntity <PharmacyItemPharmacy>(x => x.PharmacyItemId == branchId)?.FirstOrDefault(); if (pharmacyItem != null) { _dataService.Remove(pharmacyItem); } if (model.PharmacyId != null) { _dataService.Add(new PharmacyItemPharmacy() { PharmacyId = model.PharmacyId.Value, PharmacyItemId = branchId }); } var entityEnumRecords = _dataService.GetEntity <EntityEnumRecords>(x => x.EntityId == branchId).ToList(); if (entityEnumRecords.Count > 0) { entityEnumRecords.ForEach(x => _dataService.Remove(x)); } //Види діяльності обрані в МПД var trlActivityTypeEnum = _dataService.GetEntity <EnumRecord>(x => x.Code == model.TrlActivityType)?.FirstOrDefault(); _dataService.Add(new EntityEnumRecords() { EntityId = branchId, EntityType = "BranchApplication", EnumRecordType = trlActivityTypeEnum?.EnumType, EnumRecordCode = trlActivityTypeEnum?.Code }); await _dataService.SaveChangesAsync(); } } return(branchId); }
public override async Task <IActionResult> Edit(Guid id, PrlContractorDetailDTO model) { if (id != model.Id) { return(NotFound()); } if (!model.ListOfBranches?.Any() ?? true) { ModelState.AddModelError("ListOfBranches", "Мае бути обрано щонайменьше одне МПД"); } if (ModelState.IsValid) { try { model.Id = _dataService.Add <PrlContractor>(model); _dataService.SaveChanges(); var branchContractors = _dataService.GetEntity <PrlBranchContractor>().Where(x => x.ContractorId == model.Id).ToList(); if (branchContractors.Count > 0) { branchContractors.ForEach(x => _dataService.Remove(x)); } model.ListOfBranches?.ForEach(branchId => _dataService.Add(new PrlBranchContractor() { ContractorId = model.Id, BranchId = branchId })); _dataService.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (await Service.GetListDTO().SingleOrDefaultAsync(x => x.Id == id) == null) { return(await Task.Run(() => NotFound())); } else { throw; } } return(RedirectToAction("Details", "PrlApp", new { Area = "PRL", Id = model.appId }, "prlContractor")); } var branchIds = _dataService.GetEntity <PrlBranchContractor>().Where(x => x.ContractorId == model.Id).Select(x => x.BranchId); model.ListOfBranches = branchIds.ToList(); IEnumerable <BranchListDTO> branchList; if (model.Sort == "AddBranchApplication") { branchList = await _dataService.GetDtoAsync <BranchListDTO>(x => x.ApplicationId == model.appId && x.IsFromLicense != true); } else { branchList = await _dataService.GetDtoAsync <BranchListDTO>(x => x.ApplicationId == model.appId); } ViewBag.multiSelectBranchList = new MultiSelectList(branchList, nameof(BranchListDTO.Id), nameof(BranchListDTO.Name)); return(View(model)); }
public override async Task <IActionResult> Edit(Guid id, EDocumentDetailsDTO model) { if (id != model.Id) { return(NotFound()); } var fileList = _dataService.GetEntity <FileStore>().Where(x => x.EntityId == id).Select(x => x.EntityId).ToList(); IEnumerable <BranchListDTO> branchList; if (model.AppSort == "AddBranchApplication") { branchList = await _dataService.GetDtoAsync <BranchListDTO>(x => x.ApplicationId == model.ApplicationId && x.IsFromLicense != true); } else { branchList = await _dataService.GetDtoAsync <BranchListDTO>(x => x.ApplicationId == model.ApplicationId); } if (fileList.Count == 0) { if (model.AppType == "TRL") { ViewBag.selectBranchList = new SelectList(branchList.Select(p => new { p.Id, p.Name }), nameof(BranchListDTO.Id), nameof(BranchListDTO.Name)); } else { var multiselectlist = new MultiSelectList(branchList, nameof(BranchListDTO.Id), nameof(BranchListDTO.Name)); ViewBag.multiSelectBranchList = multiselectlist; } ModelState.AddModelError("", "Мае бути додано щонайменьше однин файл"); //return await Task.FromResult(Json(new { success = false, ErrorMessage = "Мае бути додано щонайменьше однин файл" })); return(View(model)); } var branchIds = _dataService.GetEntity <BranchEDocument>().Where(x => x.EDocumentId == id).Select(x => x.BranchId); if (model.AppSort != "AddBranchApplication" && (!model.ListOfBranches?.Any() ?? true) && model.AppType != "TRL") { model.ListOfBranches = branchIds.ToList(); var multiselectlist = new MultiSelectList(branchList, nameof(BranchListDTO.Id), nameof(BranchListDTO.Name)); ViewBag.multiSelectBranchList = multiselectlist; ModelState.Clear(); ModelState.AddModelError("ListOfBranches", "Мае бути обрано щонайменьше одне МПД"); return(View(model)); } if (model.AppType == "TRL" && model.BranchId == null) { ViewBag.selectBranchList = new SelectList(branchList.Select(p => new { p.Id, p.Name }), nameof(BranchListDTO.Id), nameof(BranchListDTO.Name)); ModelState.Clear(); ModelState.AddModelError("BrancheId", "Оберіть МПД"); return(View(model)); } try { model.Id = _dataService.Add <EDocument>(model); _dataService.SaveChanges(); var branchContractors = _dataService.GetEntity <BranchEDocument>().Where(x => x.EDocumentId == model.Id).ToList(); if (branchContractors.Count > 0) { branchContractors.ForEach(x => _dataService.Remove(x)); } if (model.AppType == "TRL") { _dataService.Add(new BranchEDocument { EDocumentId = model.Id, BranchId = model.BranchId.Value }); } else { model.ListOfBranches?.ForEach(branchId => _dataService.Add(new BranchEDocument { EDocumentId = model.Id, BranchId = branchId })); } _dataService.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (await Service.GetListDTO().SingleOrDefaultAsync(x => x.Id == id) == null) { return(NotFound()); } else { throw; } } var appType = (await _dataService.GetDtoAsync <AppStateDTO>(x => x.Id == model.ApplicationId)).FirstOrDefault()?.AppType; switch (appType) { case "PRL": return(RedirectToAction("Details", "Application", new { Area = "PRL", Id = model.ApplicationId }, "eDocument")); case "IML": return(RedirectToAction("Details", "Application", new { Area = "IML", Id = model.ApplicationId }, "eDocument")); case "TRL": return(RedirectToAction("Details", "Application", new { Area = "TRL", Id = model.ApplicationId }, "eDocument")); default: return(NotFound()); } }