public async Task <IActionResult> EditBulletin(CasePersonSentenceBulletinEditVM model) { SetViewBagBulletin(model.CasePersonId); if (model.LawUnitSignId <= 0) { ModelState.AddModelError(nameof(CasePersonSentenceBulletinEditVM.LawUnitSignId), "Изберете подписващ съдия"); } if (!ModelState.IsValid) { return(View(nameof(EditBulletin), model)); } var currentId = model.Id; (bool result, string errorMessage) = service.CasePersonSentenceBulletin_SaveData(model); if (result == true) { await SaveFileBulletin(model.Id); this.SaveLogOperation(currentId == 0, model.Id); SetSuccessMessage(MessageConstant.Values.SaveOK); return(RedirectToAction(nameof(EditBulletin), new { id = model.Id })); } else { SetErrorMessage(string.IsNullOrEmpty(errorMessage) == false ? errorMessage : MessageConstant.Values.SaveFailed); } return(View(nameof(EditBulletin), model)); }
/// <summary> /// Добавяне на бюлетин към лице /// </summary> /// <param name="personId"></param> /// <returns></returns> public IActionResult AddBulletin(int personId) { var bulletin = service.CasePersonSentenceBulletin_GetByIdPerson(personId); if (bulletin == null) { SetViewBagBulletin(personId); var caseSentence = service.CasePersonSentence_GetByPerson(personId); var caseModel = service.GetById <Case>(caseSentence.CaseId); var caseLawUnit = lawUnitService.GetJudgeReporter(caseSentence.CaseId); DateTime?birthDay = caseSentence.CasePerson.UicTypeId == NomenclatureConstants.UicTypes.EGN ? Utils.Validation.GetBirthDayFromEgn(caseSentence.CasePerson.Uic) : null; var model = new CasePersonSentenceBulletinEditVM() { CasePersonId = personId, CaseId = caseSentence.CaseId, CourtId = userContext.CourtId, CaseTypeId = caseModel.CaseTypeId, SentenceDescription = caseSentence.Description.Replace(Environment.NewLine, "<p>"), LawUnitSignId = caseLawUnit != null ? caseLawUnit.LawUnitId : 0, }; if (birthDay != null) { model.BirthDay = (DateTime)birthDay; } return(View(nameof(EditBulletin), model)); } else { return(RedirectToAction(nameof(EditBulletin), new { id = bulletin.Id })); } }
/// <summary> /// Запис на бюлетин /// </summary> /// <param name="model"></param> /// <returns></returns> public (bool result, string errorMessage) CasePersonSentenceBulletin_SaveData(CasePersonSentenceBulletinEditVM model) { try { if (model.Id == 0) { var exists = repo.AllReadonly <CasePersonSentenceBulletin>() .Where(x => x.Id != model.Id) .Where(x => x.CasePersonId == model.CasePersonId) .Any(); if (exists == true) { return(result : false, errorMessage : "Вече има въведени данни"); } } CasePersonSentenceBulletin saved = null; if (model.Id > 0) { //Update saved = repo.GetById <CasePersonSentenceBulletin>(model.Id); repo.Update(saved); } else { saved = new CasePersonSentenceBulletin(); saved.CasePersonId = model.CasePersonId; saved.CaseId = model.CaseId; saved.CourtId = model.CourtId; } saved.BirthDayPlace = model.BirthDayPlace; saved.BirthDay = model.BirthDay; saved.Nationality = model.Nationality; saved.FamilyMarriage = model.FamilyMarriage; saved.FatherName = model.FatherName; saved.MotherName = model.MotherName; saved.SentenceDescription = model.SentenceDescription; saved.UserId = userContext.UserId; saved.DateWrt = DateTime.Now; saved.IsAdministrativePunishment = model.IsAdministrativePunishment; saved.IsConvicted = model.IsConvicted; saved.LawUnitSignId = model.LawUnitSignId; if (model.Id > 0) { repo.Update(saved); } else { repo.Add <CasePersonSentenceBulletin>(saved); } repo.SaveChanges(); model.Id = saved.Id; return(result : true, errorMessage : ""); } catch (Exception ex) { logger.LogError(ex, $"Грешка при запис на CasePersonSentenceBulletin Id={ model.Id }"); return(result : false, errorMessage : Helper.GlobalConstants.MessageConstant.Values.SaveFailed); } }