public IActionResult LoadByCaseGroup(CaseSelectionProtokolVM model) { IEnumerable <CaseSelectionProtokolLawUnitVM> modelView = null; ViewBag.RoleId = NomenclatureConstants.JudgeRole.Judge; modelView = service.LawUnit_LoadJudgeByCaseGroup(userContext.CourtId, model.CaseGroupId, model.IdStr ?? "", model.CaseId, model.JudgeRoleId); SetViewBagLawUnits(NomenclatureConstants.SelectionMode.SelectByGroups); return(PartialView("_LoadedLawUnits", modelView)); }
//Създава един ред за за общо разпределените и средно дневните дела в дневна таблица дела ако няма такъв. public bool MakeDaylyLoadPeriodLawuitRowsTotal(CaseSelectionProtokolVM caseSelectionProtocol, int courtLoadPeriodId, bool IsDuty) { bool res = true; try { List <CourtLoadPeriodLawUnit> courtLoadPeriodLawUnitTotal = null; if (IsDuty) { courtLoadPeriodLawUnitTotal = repo.All <CourtLoadPeriodLawUnit>() .Where(x => x.CourtLoadPeriodId == courtLoadPeriodId) .Where(x => x.LawUnitId == null) .ToList(); } else { courtLoadPeriodLawUnitTotal = repo.All <CourtLoadPeriodLawUnit>() .Where(x => x.CourtLoadPeriodId == courtLoadPeriodId) .Where(x => x.LawUnitId == null) .Where(x => x.SelectionDate.Date == DateTime.Now.Date) .ToList(); } if (courtLoadPeriodLawUnitTotal.Count == 0) { CourtLoadPeriodLawUnit currentCourtLoadPeriodLawUnit = new CourtLoadPeriodLawUnit(); currentCourtLoadPeriodLawUnit.CourtLoadPeriodId = courtLoadPeriodId; currentCourtLoadPeriodLawUnit.LawUnitId = null; currentCourtLoadPeriodLawUnit.SelectionDate = DateTime.Now.Date; currentCourtLoadPeriodLawUnit.IsAvailable = true; currentCourtLoadPeriodLawUnit.DayCases = 0; currentCourtLoadPeriodLawUnit.TotalDayCases = 0; currentCourtLoadPeriodLawUnit.LoadIndex = 0; currentCourtLoadPeriodLawUnit.AverageCases = 0; repo.Add <CourtLoadPeriodLawUnit>(currentCourtLoadPeriodLawUnit); repo.SaveChanges(); } } catch (Exception ex) { res = false; logger.LogError(ex, $"Грешка при запис на обобщена информация за разпределение за courtLoadPeriodId={ courtLoadPeriodId}"); } return(res); }
private void SetSelectedTabBySelectionMode(CaseSelectionProtokolVM model) { switch (model.SelectionModeId) { case NomenclatureConstants.SelectionMode.SelectByGroups: model.SelectedTab = "#tabSelectByGroup"; break; case NomenclatureConstants.SelectionMode.ManualSelect: model.SelectedTab = "#tabManualSelect"; break; case NomenclatureConstants.SelectionMode.SelectByDuty: model.SelectedTab = "#tabSelectByDuty"; break; } }
void SetDataError(CaseSelectionProtokolVM model) { SetSelectedTabBySelectionMode(model); SetViewBagLawUnits(model.SelectionModeId); if (model.SelectionModeId == NomenclatureConstants.SelectionMode.ManualSelect) { for (int i = 0; i < model.LawUnits.Count(); i++) { model.LawUnits[i].LawUnitTypeId = NomenclatureConstants.LawUnitTypes.Judge.ToString(); if (NomenclatureConstants.JudgeRole.JuriRolesList.Contains(model.JudgeRoleId)) { //if (model.JudgeRoleId == NomenclatureConstants.JudgeRole.Jury || model.JudgeRoleId == NomenclatureConstants.JudgeRole.ReserveJury) model.LawUnits[i].LawUnitTypeId = NomenclatureConstants.LawUnitTypes.Jury.ToString(); } } } }
public IActionResult Add(int caseId) { if (!CheckAccess(service, SourceTypeSelectVM.CaseSelectionProtokol, null, AuditConstants.Operations.Append, caseId)) { return(Redirect_Denied()); } var tcase = service.GetById <Case>(caseId); var model = new CaseSelectionProtokolVM() { CaseId = caseId, CourtId = tcase.CourtId, CaseGroupId = tcase.CaseGroupId, CaseCodeId = tcase.CaseCodeId ?? 0, CourtGroupId = tcase.CourtGroupId, SelectionModeId = 1 }; SetViewBag(model.CourtId, caseId); var caseGroups = service.CaseGroup_WithLawUnits(model.CourtId, ""); if (caseGroups.Length == 0) { SetErrorMessage("Няма налични съдии за избор. Бутон \"Запис\" ще генерира протокол за липса на съдии!"); } if (service.HsaUnsignedProtocol(caseId)) { SetErrorMessage("Не може да бъде създаден нов протокол, докато има неподписан такъв."); return(RedirectToAction("Index", new { id = caseId })); } else { if (ViewBag.countAvailableJudgeRole > 0) { return(View(nameof(Edit), model)); } else { SetErrorMessage("Съдебният състав по делото е запълнен. Не могат да бъдат добавени повече позиции."); return(RedirectToAction("Index", new { id = caseId })); } } }
//Изчисляване на коефициента за разпределение според коефициента public CaseSelectionProtokolVM CalculateAllKoef(CaseSelectionProtokolVM caseSelectionProtocol) { if (caseSelectionProtocol.SelectionModeId != NomenclatureConstants.SelectionMode.SelectByDuty) { caseSelectionProtocol.CourtDutyId = null; } CourtLoadPeriod courtLoadPeriod = GetLoadPeriod(caseSelectionProtocol.CourtGroupId, caseSelectionProtocol.CourtDutyId); int totalPeriodDays = repo.AllReadonly <CourtLoadPeriodLawUnit>() .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id) .Where(x => (x.LawUnitId ?? 0) == 0) .Count(); decimal totalKoef = 0; // foreach (var lawUnit in caseSelectionProtocol.LawUnits.Where(x => NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(x.StateId))) foreach (var lawUnit in caseSelectionProtocol.LawUnits) { CalculateLawUnitDataInGroup(lawUnit, courtLoadPeriod.Id); totalKoef = totalKoef + lawUnit.Koef; } // foreach (var lawUnit in caseSelectionProtocol.LawUnits.Where(x => NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(x.StateId))) foreach (var lawUnit in caseSelectionProtocol.LawUnits) { lawUnit.KoefNormalized = lawUnit.Koef / totalKoef * 100M; ////Когато нормализираният коефициент е прекалено малък го приравняваме на 1 за да има поне 1 участие като вероятност //if ((lawUnit.KoefNormalized > 0) && (lawUnit.KoefNormalized < 1)) //{ lawUnit.KoefNormalized = 1; } int lawUnitPeriodDays = repo.AllReadonly <CourtLoadPeriodLawUnit>() .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id) .Where(x => x.LawUnitId == lawUnit.LawUnitId) .Count(); lawUnit.CasesCountIfWorkAllPeriodInGroup = (decimal)totalPeriodDays / (decimal)lawUnitPeriodDays * 100M / (decimal)lawUnit.LoadIndex * lawUnit.CaseCount; lawUnit.ExcludeByBigDeviation = false; } return(caseSelectionProtocol); }
public IActionResult LoadByCaseGroup(string idStr, string groups, int caseId) { var ddl_list = service.Return_Available_CaseGroup_forAdditionalSelect(idStr, groups, caseId); ViewBag.CaseGroupId_ddl = ddl_list; CaseSelectionProtokolVM model = new CaseSelectionProtokolVM(); model.IdStr = idStr; model.CaseId = caseId; if (ddl_list.Count > 0) { return(PartialView(model)); } else { return(Content("empty")); } }
//При Разпределение Създава инициализиращи редове за ДЕНЯ за всички участници в разпределението, за които все още не са създадени public bool MakeDaylyLoadPeriodLawuitRowsByGroup(CaseSelectionProtokolVM caseSelectionProtocol) { bool res = true; //Expression<Func<CourtLoadPeriod, bool>> courtGroupDutySearch = x => true; //if (caseSelectionProtocol.CourtGroupId != null) //{ // courtGroupDutySearch = x => x.CourtGroupId == caseSelectionProtocol.CourtGroupId; //} //if (caseSelectionProtocol.CourtDutyId != null) //{ // courtGroupDutySearch = x => x.CourtDutyId == caseSelectionProtocol.CourtDutyId; //} //var courtLoadPeriod = repo.AllReadonly<CourtLoadPeriod>() // .Include(x => x.CourtLoadResetPeriod) // .Where(x => x.CourtLoadResetPeriod.DateFrom <= DateTime.Now) // .Where(x => (x.CourtLoadResetPeriod.DateTo ?? DateTime.Now) >= DateTime.Now) // .Where(courtGroupDutySearch).FirstOrDefault(); if (caseSelectionProtocol.SelectionModeId != NomenclatureConstants.SelectionMode.SelectByDuty) { caseSelectionProtocol.CourtDutyId = null; } var courtLoadPeriod = GetLoadPeriod(caseSelectionProtocol.CourtGroupId, caseSelectionProtocol.CourtDutyId); bool isDuty = (caseSelectionProtocol.CourtDutyId ?? 0) > 0; if (courtLoadPeriod != null) { MakeDaylyLoadPeriodLawuitRowsTotal(caseSelectionProtocol, courtLoadPeriod.Id, isDuty); foreach (var lawUnit in caseSelectionProtocol.LawUnits) { MakeDaylyLoadPeriodLawuitRowsForLowUnit(caseSelectionProtocol, courtLoadPeriod.Id, lawUnit.LawUnitId, isDuty); } } ; return(res); }
public IActionResult Edit(CaseSelectionProtokolVM model) { bool ExitByTime = false; SetViewBag(model.CourtId, model.CaseId); ViewBag.RoleId = model.JudgeRoleId; ValidateModel(model); if (!ModelState.IsValid) { SetDataError(model); return(View(nameof(Edit), model)); } var currentId = model.Id; string errorMessage = ""; bool save = true; if (NomenclatureConstants.JudgeRole.JuriRolesList.Contains(model.JudgeRoleId)) { int protokolId = service.Select_Create_AddJuryProtocol(model, ref errorMessage); if (protokolId > 0) { model.Id = protokolId; return(RedirectToAction("SignDoc", new { id = model.Id })); } else { save = false; } } else { /////////////////////////////////////////////////////////////////////////////// ///Взема се номер и се коригира /// ///////////////////////////////////////////////////////////////////////////////// ///////////////Denislav Angelov 2020.08.27 //int currentLockNumber = service.TakeCaseSelectionProtocolLockNumber(model.CourtGroupId, model.CourtDutyId); //Random rnd = new Random(); //int ms = rnd.Next(100); //Thread.Sleep(ms); //int minLockNumber = service.TakeCaseSelectionProtocolMinLockNumber(model.CourtGroupId, model.CourtDutyId); //DateTime timeStart = DateTime.Now; //while (currentLockNumber != minLockNumber) //{ // Thread.Sleep(100); // minLockNumber = service.TakeCaseSelectionProtocolMinLockNumber(model.CourtGroupId, model.CourtDutyId); // if (timeStart.AddSeconds(60)<DateTime.Now) // { // ExitByTime = true; // break; // } //} //if (ExitByTime==false) //{ // if (service.HsaUnsignedProtocol(model.CaseId)) // { // SetErrorMessage("Не може да бъде създаден нов протокол, докато има неподписан такъв."); // return RedirectToAction("Index", new { id = model.CaseId }); // } ///////////////Denislav Angelov 2020.08.27 if (!service.CaseSelectionProtokol_SaveData(model, ref errorMessage)) { save = false; } ///////////////Denislav Angelov 2020.08.27 //} //else //{ // save = false; //} //service.FinishLockNumber(currentLockNumber); ///////////////Denislav Angelov 2020.08.27 /////////////////////////////////////////////////////////////////////////////// } if (save == true) { SetAuditContext(service, SourceTypeSelectVM.CaseSelectionProtokol, model.Id, currentId == 0); //this.SaveLogOperation(currentId == 0, model.Id); SetSuccessMessage(MessageConstant.Values.SaveOK); } else { if (errorMessage == "") { errorMessage = MessageConstant.Values.SaveFailed; } if (ExitByTime) { errorMessage = MessageConstant.Values.TimeoutSelectProtokol; } SetErrorMessage(errorMessage); SetDataError(model); return(View(nameof(Edit), model)); } //В случай няма наличен състав се отива на подпис var saved_model = service.CaseSelectionProtokol_Preview(model.Id); var comparentmentLisCount = service.GetJudgeComprentmetList((saved_model.SelectedLawUnitId ?? 0), saved_model.CourtId, saved_model.CaseId).Count; if (comparentmentLisCount > 1) { return(RedirectToAction("PreviewDoc", new { id = model.Id })); } else { var res = service.CaseSelectionProtokol_UpdateBeforeDocForSign(saved_model); return(RedirectToAction("SignDoc", new { id = saved_model.Id })); } // return RedirectToAction("PreviewDoc", new { id = model.Id }); }
void ValidateModel(CaseSelectionProtokolVM model) { if (model.SelectionModeId == NomenclatureConstants.SelectionMode.ManualSelect && model.Description == null) { ModelState.AddModelError("", "Моля, въведете основание за ръчен избор"); } if (model.SelectionModeId == NomenclatureConstants.SelectionMode.ManualSelect && model.Description != null && NomenclatureConstants.JudgeRole.JuriRolesList.Contains(model.JudgeRoleId)) { if (service.GetActiveLawUnits(model.CaseId).Contains(model.LawUnits.FirstOrDefault().LawUnitId)) { ModelState.AddModelError("", "Съдебният заседател вече е добавен в делото "); } } if (NomenclatureConstants.JudgeRole.JuriRolesList.Contains(model.JudgeRoleId) && model.SelectionModeId != NomenclatureConstants.SelectionMode.ManualSelect) { var jury = service.LawUnit_LoadJury(model.CourtId, model.CaseId, model.SpecialityId); if (jury.Count() == 0) { ModelState.AddModelError("", "Няма повече налични съдебни заседатели"); } } if (NomenclatureConstants.JudgeRole.JuriRolesList.Contains(model.JudgeRoleId)) // if (model.JudgeRoleId == NomenclatureConstants.JudgeRole.Jury || model.JudgeRoleId == NomenclatureConstants.JudgeRole.ReserveJury) { string errorDescription = ""; for (int i = 0; i < model.LawUnits.Count(); i++) { var lawUnit = model.LawUnits[i]; if (lawUnit.StateId == NomenclatureConstants.SelectionProtokolLawUnitState.AddedManually && lawUnit.LawUnitId <= 0) { ModelState.AddModelError($"{nameof(CaseSelectionProtokolVM.LawUnits)}[{i}].{nameof(CaseSelectionProtokolLawUnitVM.LawUnitId)}", "Моля, въведете участник"); } if (lawUnit.StateId == NomenclatureConstants.SelectionProtokolLawUnitState.Exclude && lawUnit.Description == null) { errorDescription = "Моля, въведете причина за неучастие на " + lawUnit.LawUnitFullName; ModelState.AddModelError($"{nameof(CaseSelectionProtokolVM.LawUnits)}[{i}].{nameof(CaseSelectionProtokolLawUnitVM.Description)}", errorDescription); } } } else { string errorDescription = ""; bool hasActiveCourtGroup = false; bool hasCaseGroup = false; for (int i = 0; i < model.LawUnits.Count(); i++) { var lawUnit = model.LawUnits[i]; //Проверява дали има валидни съдии от групата на делото и от някое направление добавени if (lawUnit.CaseGroupId != null) { hasCaseGroup = true; } if (lawUnit.CaseGroupId == null && NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(lawUnit.StateId)) { hasActiveCourtGroup = true; } if (lawUnit.StateId == NomenclatureConstants.SelectionProtokolLawUnitState.Exclude && lawUnit.Description == null) { errorDescription = "Моля, въведете причина за неучастие на " + lawUnit.LawUnitFullName; ModelState.AddModelError($"{nameof(CaseSelectionProtokolVM.LawUnits)}[{i}].{nameof(CaseSelectionProtokolLawUnitVM.Description)}", errorDescription); } //if (lawUnit.StateId == NomenclatureConstants.SelectionProtokolLawUnitState.AddedManually && lawUnit.Description == null) //{ // errorDescription = "Моля, въведете причина за ръчен избор на " + lawUnit.LawUnitFullName; // ModelState.AddModelError($"{nameof(CaseSelectionProtokolVM.LawUnits)}[{i}].{nameof(CaseSelectionProtokolLawUnitVM.Description)}", errorDescription); //} } bool hasActiveLawUnit = model.LawUnits.Where(x => NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(x.StateId) && x.LawUnitId > 0).Any(); if (hasActiveLawUnit == false) { string idStr = ""; foreach (var item in model.LawUnits) { idStr = idStr + item.LawUnitId.ToString() + ","; } var available_users_in_otherGroups = service.Return_Available_CaseGroup_forAdditionalSelect(idStr, "", model.CaseId); if (available_users_in_otherGroups.Count > 0) { ModelState.AddModelError("", "Въведете поне едно активно лице"); } else { model.IsProtokolNoSelection = true; } } if (hasCaseGroup == true && hasActiveCourtGroup == true) { ModelState.AddModelError("", "Има активен съдия от групата на делото и добавен съдия от отделение"); } } }
//Създава един ред за потребител в дневна таблица сразпределени дела ако няма такъв. //Ако до сега няма такъв дава за стартова стойност на средно дневни сума на всички среднодневни до днес public bool MakeDaylyLoadPeriodLawuitRowsForLowUnit(CaseSelectionProtokolVM caseSelectionProtocol, int courtLoadPeriodId, int lawUnitId, bool IsDuty) { bool res = true; try { var courtLoadPeriodLawUnit = repo.All <CourtLoadPeriodLawUnit>() .Where(x => x.CourtLoadPeriodId == courtLoadPeriodId) .Where(x => x.LawUnitId == lawUnitId); //.Where(x => x.SelectionDate.Date == DateTime.Now.Date) if (IsDuty) //По дежурство { if (courtLoadPeriodLawUnit.ToList().Count == 0) { var courtLoadPeriodLawUnitTotal = repo.All <CourtLoadPeriodLawUnit>() .Where(x => x.CourtLoadPeriodId == courtLoadPeriodId) .Where(x => x.LawUnitId == null); var curentLawUnit = caseSelectionProtocol.LawUnits.Where(x => x.LawUnitId == lawUnitId).FirstOrDefault(); CourtLoadPeriodLawUnit currentCourtLoadPeriodLawUnit = new CourtLoadPeriodLawUnit(); currentCourtLoadPeriodLawUnit.CourtLoadPeriodId = courtLoadPeriodId; currentCourtLoadPeriodLawUnit.LawUnitId = lawUnitId; currentCourtLoadPeriodLawUnit.SelectionDate = DateTime.Now.Date; currentCourtLoadPeriodLawUnit.IsAvailable = true; currentCourtLoadPeriodLawUnit.DayCases = 0; currentCourtLoadPeriodLawUnit.TotalDayCases = 0; currentCourtLoadPeriodLawUnit.LoadIndex = curentLawUnit.LoadIndex; currentCourtLoadPeriodLawUnit.AverageCases = 0; repo.Add <CourtLoadPeriodLawUnit>(currentCourtLoadPeriodLawUnit); repo.SaveChanges(); } } else //В Група { if (courtLoadPeriodLawUnit.Where(x => x.SelectionDate.Date == DateTime.Now.Date).ToList().Count == 0) { var courtLoadPeriodLawUnitTotal = repo.All <CourtLoadPeriodLawUnit>() .Where(x => x.CourtLoadPeriodId == courtLoadPeriodId) .Where(x => x.LawUnitId == null); var curentLawUnit = caseSelectionProtocol.LawUnits.Where(x => x.LawUnitId == lawUnitId).FirstOrDefault(); CourtLoadPeriodLawUnit currentCourtLoadPeriodLawUnit = new CourtLoadPeriodLawUnit(); currentCourtLoadPeriodLawUnit.CourtLoadPeriodId = courtLoadPeriodId; currentCourtLoadPeriodLawUnit.LawUnitId = lawUnitId; currentCourtLoadPeriodLawUnit.SelectionDate = DateTime.Now.Date; if (curentLawUnit.StateId == NomenclatureConstants.SelectionProtokolLawUnitState.Absent) { currentCourtLoadPeriodLawUnit.IsAvailable = false; } else { currentCourtLoadPeriodLawUnit.IsAvailable = true; } currentCourtLoadPeriodLawUnit.DayCases = 0; currentCourtLoadPeriodLawUnit.TotalDayCases = 0; currentCourtLoadPeriodLawUnit.LoadIndex = curentLawUnit.LoadIndex; currentCourtLoadPeriodLawUnit.AverageCases = 0; //Когато този потребител се включва на по късен етап и получава приравнителни средно дневни if (courtLoadPeriodLawUnit.ToList().Count == 0 && courtLoadPeriodLawUnitTotal.Where(x => x.SelectionDate < DateTime.Now.Date).ToList().Count > 0) { foreach (var row in courtLoadPeriodLawUnitTotal.Where(x => x.SelectionDate != DateTime.Now.Date).ToList()) { currentCourtLoadPeriodLawUnit.AverageCases = currentCourtLoadPeriodLawUnit.AverageCases + row.AverageCases; currentCourtLoadPeriodLawUnit.TotalDayCases = currentCourtLoadPeriodLawUnit.TotalDayCases + row.AverageCases; } repo.Add <CourtLoadPeriodLawUnit>(currentCourtLoadPeriodLawUnit); repo.SaveChanges(); } else //Когато този потребител има разпределения до момента в групата -Нормално разпределение за следващ ден { //Ако все още няма разпределение за текущия ден if (courtLoadPeriodLawUnit.Where(x => x.SelectionDate == DateTime.Now.Date).ToList().Count == 0) { repo.Add <CourtLoadPeriodLawUnit>(currentCourtLoadPeriodLawUnit); repo.SaveChanges(); } } } } } catch (Exception ex) { res = false; logger.LogError(ex, $"Грешка при запис на информация за разпределение член съдебен състав lawUnitId={ lawUnitId}"); } return(res); }
public void MergeCaseSelectionProtokolAndVM(CaseSelectionProtokol caseSelectionProtokol, CaseSelectionProtokolVM caseSelectionProtokolVM) { foreach (var item in caseSelectionProtokol.LawUnits) { foreach (var vm_item in caseSelectionProtokolVM.LawUnits) { if (item.LawUnitId == vm_item.LawUnitId) { item.CaseCount = vm_item.CaseCount; } } } }
public IActionResult Edit(CaseSelectionProtokolVM model) { bool ExitByTime = false; SetViewBag(model.CourtId, model.CaseId); ViewBag.RoleId = model.JudgeRoleId; ValidateModel(model); if (!ModelState.IsValid) { SetDataError(model); return(View(nameof(Edit), model)); } var currentId = model.Id; string errorMessage = ""; bool save = true; if (NomenclatureConstants.JudgeRole.JuriRolesList.Contains(model.JudgeRoleId)) { int protokolId = service.Select_Create_AddJuryProtocol(model, ref errorMessage); if (protokolId > 0) { model.Id = protokolId; return(RedirectToAction("SignDoc", new { id = model.Id })); } else { save = false; } } else { if (!service.CaseSelectionProtokol_SaveData(model, ref errorMessage)) { save = false; } } if (save == true) { SetAuditContext(service, SourceTypeSelectVM.CaseSelectionProtokol, model.Id, currentId == 0); //this.SaveLogOperation(currentId == 0, model.Id); SetSuccessMessage(MessageConstant.Values.SaveOK); } else { if (errorMessage == "") { errorMessage = MessageConstant.Values.SaveFailed; } if (ExitByTime) { errorMessage = MessageConstant.Values.TimeoutSelectProtokol; } SetErrorMessage(errorMessage); SetDataError(model); return(View(nameof(Edit), model)); } //В случай няма наличен състав се отива на подпис var saved_model = service.CaseSelectionProtokol_Preview(model.Id); var comparentmentLisCount = service.GetJudgeComprentmetList((saved_model.SelectedLawUnitId ?? 0), saved_model.CourtId, saved_model.CaseId).Count; if (comparentmentLisCount > 1) { return(RedirectToAction("PreviewDoc", new { id = model.Id })); } else { var res = service.CaseSelectionProtokol_UpdateBeforeDocForSign(saved_model); return(RedirectToAction("SignDoc", new { id = saved_model.Id })); } // return RedirectToAction("PreviewDoc", new { id = model.Id }); }
//Изчисляване на коефициента за разпределение според коефициента public CaseSelectionProtokolVM CalculateAllKoef(CaseSelectionProtokolVM caseSelectionProtocol) { if (caseSelectionProtocol.SelectionModeId != NomenclatureConstants.SelectionMode.SelectByDuty) { caseSelectionProtocol.CourtDutyId = null; } CourtLoadPeriod courtLoadPeriod = GetLoadPeriod(caseSelectionProtocol.CourtGroupId, caseSelectionProtocol.CourtDutyId); //Optimisacia2020.01.09 s //int totalPeriodDays = repo.AllReadonly<CourtLoadPeriodLawUnit>() // .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id) // .Where(x => (x.LawUnitId ?? 0) == 0) // .Count(); //Optimisacia2020.01.09 e decimal totalKoef = 0; //2020.01.08 Optimisation List <int> LawUnitsArray = caseSelectionProtocol.LawUnits.Select(x => x.LawUnitId).ToList(); LawUnitsArray.Add(0); // foreach (var lawUnit in caseSelectionProtocol.LawUnits.Where(x => NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(x.StateId))) var courtLoadPeriodLawunitsList = repo.AllReadonly <CourtLoadPeriodLawUnit>().Where(x => LawUnitsArray.Contains(x.LawUnitId ?? 0)) .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id).ToList(); //Optimisacia2020.01.09 s int totalPeriodDays = courtLoadPeriodLawunitsList .Where(x => (x.LawUnitId ?? 0) == 0) .Count(); //Optimisacia2020.01.09 e foreach (var lawUnit in caseSelectionProtocol.LawUnits) { // CalculateLawUnitDataInGroup(lawUnit, courtLoadPeriod.Id); CalculateLawUnitDataInGroup(lawUnit, courtLoadPeriod.Id, courtLoadPeriodLawunitsList); //2020.01.08 Optimisation totalKoef = totalKoef + lawUnit.Koef; } // foreach (var lawUnit in caseSelectionProtocol.LawUnits.Where(x => NomenclatureConstants.SelectionProtokolLawUnitState.ActiveState.Contains(x.StateId))) foreach (var lawUnit in caseSelectionProtocol.LawUnits) { lawUnit.KoefNormalized = lawUnit.Koef / totalKoef * 100M; ////Когато нормализираният коефициент е прекалено малък го приравняваме на 1 за да има поне 1 участие като вероятност //if ((lawUnit.KoefNormalized > 0) && (lawUnit.KoefNormalized < 1)) //{ lawUnit.KoefNormalized = 1; } //2020.01.08 Optimisation 1 //int lawUnitPeriodDays = repo.AllReadonly<CourtLoadPeriodLawUnit>() // .Where(x => x.CourtLoadPeriodId == courtLoadPeriod.Id) // .Where(x => x.LawUnitId == lawUnit.LawUnitId) // .Where(x => x.AverageCases == 0) // .Count(); int lawUnitPeriodDays = courtLoadPeriodLawunitsList .Where(x => x.LawUnitId == lawUnit.LawUnitId) .Where(x => x.AverageCases == 0) .Count(); //2020.01.08 Optimisation 1 if (lawUnitPeriodDays == 0) { lawUnitPeriodDays = 1; } if (lawUnit.LoadIndex == 0) { lawUnit.LoadIndex = 100; } lawUnit.CasesCountIfWorkAllPeriodInGroup = (decimal)totalPeriodDays / (decimal)lawUnitPeriodDays * 100M / (decimal)lawUnit.LoadIndex * lawUnit.CaseCount; lawUnit.ExcludeByBigDeviation = false; } return(caseSelectionProtocol); }