public (bool result, string errorMessage) CourtLawUnit_SaveData(CourtLawUnit model) { try { //Проверка за припокриване на периоди DateTime dateNow = DateTime.Now.Date; var exists = repo.AllReadonly <CourtLawUnit>() .Where(x => x.Id != model.Id && x.CourtId == model.CourtId && x.PeriodTypeId == model.PeriodTypeId && x.LawUnitId == model.LawUnitId && ((x.DateTo ?? dateNow).Date >= model.DateFrom.Date && (x.DateTo ?? dateNow).Date <= (model.DateTo ?? dateNow).Date || (model.DateTo ?? dateNow).Date >= x.DateFrom.Date && (model.DateTo ?? dateNow).Date <= (x.DateTo ?? dateNow).Date) ).Any(); if (exists == true) { return(result : false, errorMessage : "За избрания служител вече има въведени данни за въведения период."); } //Ако е назначаване или преместване тогава да се сетва if (model.PeriodTypeId != NomenclatureConstants.PeriodTypes.Appoint && model.PeriodTypeId != NomenclatureConstants.PeriodTypes.Move) { model.CourtOrganizationId = null; model.LawUnitPositionId = null; } model.CourtOrganizationId = (model.CourtOrganizationId ?? 0) <= 0 ? null : model.CourtOrganizationId; model.LawUnitPositionId = (model.LawUnitPositionId ?? 0) <= 0 ? null : model.LawUnitPositionId; if (model.Id > 0) { //Update var saved = repo.GetById <CourtLawUnit>(model.Id); saved.LawUnitId = model.LawUnitId; saved.DateFrom = model.DateFrom; saved.DateTo = model.DateTo; saved.CourtOrganizationId = model.CourtOrganizationId; saved.LawUnitPositionId = model.LawUnitPositionId; saved.Description = model.Description; repo.Update(saved); repo.SaveChanges(); } else { //Insert repo.Add <CourtLawUnit>(model); repo.SaveChanges(); } return(result : true, errorMessage : ""); } catch (Exception ex) { logger.LogError(ex, $"Грешка при запис на CourtLawUnit Id={ model.Id }"); return(result : false, errorMessage : Helper.GlobalConstants.MessageConstant.Values.SaveFailed); } }
/// <summary> /// Добавяне на служител към съд /// </summary> /// <param name="periodType"></param> /// <param name="lawUnitType"></param> /// <returns></returns> public IActionResult Add(int periodType, int lawUnitType) { SetBreadcrums(periodType, lawUnitType, 0); var model = new CourtLawUnit() { CourtId = userContext.CourtId, PeriodTypeId = periodType, MasterLawUnitTypeId = lawUnitType, DateFrom = DateTime.Now }; SetViewBag(model); return(View(nameof(Edit), model)); }
void SetViewBag(CourtLawUnit model) { ViewBag.lawUnitTypeName = service.GetById <LawUnitType>(model.MasterLawUnitTypeId).Label; ViewBag.periodTypeName = service.GetById <PeriodType>(model.PeriodTypeId).Label; if (NomenclatureConstants.PeriodTypes.CurrentlyAvailable.Contains(model.PeriodTypeId)) { ViewBag.CourtOrganizationId_ddl = courtOrganizationService.CourtOrganization_SelectForDropDownList(userContext.CourtId); ViewBag.LawUnitPositionId_ddl = nomService.GetDDL_LawUnitPosition(model.MasterLawUnitTypeId); } if (model.PeriodTypeId == NomenclatureConstants.PeriodTypes.ActAs) { ViewBag.LawUnitTypeId_ddl = nomService.GetList <LawUnitType>() .Where(x => NomenclatureConstants.LawUnitTypes.CanActAsPersons.Contains(x.Id)) .OrderBy(x => x.OrderNumber) .ToSelectList(x => x.Id, x => x.Label); } }
public IActionResult Edit(CourtLawUnit model) { if (model.DateTo != null && model.DateTo.ForceStartDate() < model.DateFrom.ForceStartDate()) { ModelState.AddModelError(nameof(CourtLawUnit.DateTo), "Дата до не може да е преди Дата от"); } model.DateFrom = model.DateFrom.ForceStartDate(); model.DateTo = model.DateTo.ForceEndDate(); if (!ModelState.IsValid) { SetBreadcrums(model.PeriodTypeId, model.MasterLawUnitTypeId, model.Id); SetViewBag(model); return(View(nameof(Edit), model)); } var currentId = model.Id; (bool result, string errorMessage) = service.CourtLawUnit_SaveData(model); if (result) { this.SaveLogOperation(currentId == 0, model.Id); SetSuccessMessage(MessageConstant.Values.SaveOK); return(RedirectToAction(nameof(Edit), new { id = model.Id })); } else { if (string.IsNullOrEmpty(errorMessage)) { errorMessage = MessageConstant.Values.SaveFailed; } SetErrorMessage(errorMessage); } SetBreadcrums(model.PeriodTypeId, model.MasterLawUnitTypeId, model.Id); SetViewBag(model); return(View(nameof(Edit), model)); }
private async Task <bool> migrate_CourtLawUnit(MigrationData item) { var data = item.Data.Split('|'); try { int lawUnitTypeId = int.Parse(item.DataType.Substring(8)); string email = string.Empty; var lawUnit = new LawUnit() { LawUnitTypeId = lawUnitTypeId, UicTypeId = NomenclatureConstants.UicTypes.EGN, Uic = data[1], FirstName = data[2]?.Trim(), MiddleName = data[3]?.Trim(), FamilyName = data[4]?.Trim(), Family2Name = data[5]?.Trim(), DateFrom = DefaultDateFrom, DateWrt = DateTime.Now }; lawUnit.FullName = lawUnit.MakeFullName(); if (!string.IsNullOrEmpty(lawUnit.Uic)) { lawUnit.Person.CopyFrom(lawUnit); } else { lawUnit.Person = null; } var lawUnitPeriods = new List <CourtLawUnit>(); var appointPeriod = new CourtLawUnit(); if (!NomenclatureConstants.LawUnitTypes.NoApointmentPersons.Contains(lawUnitTypeId)) { appointPeriod.CourtId = item.CourtId; appointPeriod.DateFrom = DefaultDateFrom; appointPeriod.PeriodTypeId = NomenclatureConstants.PeriodTypes.Appoint; lawUnitPeriods.Add(appointPeriod); } switch (lawUnitTypeId) { case NomenclatureConstants.LawUnitTypes.Judge: email = data[6].Trim(); try { if (!string.IsNullOrEmpty(data[7])) { var moveToCourt = int.Parse(data[7]); var moveFromDate = data[8]; var movePeriod = new CourtLawUnit() { CourtId = moveToCourt, DateFrom = moveFromDate.StrToDateFormat("dd.MM.yyyy"), PeriodTypeId = NomenclatureConstants.PeriodTypes.Move }; if (moveToCourt < 0) { //Ако е командирован в текущия съд, се разменят двата вида период appointPeriod.PeriodTypeId = NomenclatureConstants.PeriodTypes.Move; appointPeriod.DateFrom = movePeriod.DateFrom; movePeriod.CourtId = Math.Abs(movePeriod.CourtId); movePeriod.PeriodTypeId = NomenclatureConstants.PeriodTypes.Appoint; movePeriod.DateFrom = DefaultDateFrom; } lawUnitPeriods.Add(movePeriod); } } catch { } break; case NomenclatureConstants.LawUnitTypes.MessageDeliverer: email = data[6].Trim(); break; case NomenclatureConstants.LawUnitTypes.OtherEmployee: email = data[6].Trim(); lawUnit.Department = data[7]; break; case NomenclatureConstants.LawUnitTypes.Jury: //Кой съд и специалност ако има lawUnit.Department = data[6] + ":" + (data[7] ?? ""); break; case NomenclatureConstants.LawUnitTypes.Prosecutor: //Кой съд и специалност ако има lawUnit.Code = data[6] ?? ""; lawUnit.Department = data[7] ?? ""; if (string.IsNullOrEmpty(lawUnit.Code)) { item.Message = $"{lawUnit.FullName} няма код"; return(false); } if (repo.AllReadonly <LawUnit>().Where(x => x.Code == lawUnit.Code && x.LawUnitTypeId == lawUnitTypeId).Any()) { item.Message = $"{lawUnit.Code} {lawUnit.FullName} вече съществува"; return(false); } break; default: break; } lawUnit.Courts = lawUnitPeriods; if (!string.IsNullOrEmpty(lawUnit.Uic)) { var savedLU = repo.AllReadonly <LawUnit>() .Where(x => x.Uic == lawUnit.Uic && x.UicTypeId == lawUnit.UicTypeId) .FirstOrDefault(); if (savedLU != null) { item.Message = $"{savedLU.Uic} {savedLU.FullName} вече съществува"; return(false); } } //Лицата трябва да имат уникално ЕГН и уникален email if (NomenclatureConstants.LawUnitTypes.EissUserTypes.Contains(lawUnitTypeId)) { if (string.IsNullOrEmpty(lawUnit.Uic)) { item.Message = "Лицето няма ЕГН"; return(false); } long egn; if (!long.TryParse(lawUnit.Uic, out egn)) { item.Message = "Невалидно ЕГН"; return(false); } if (string.IsNullOrEmpty(email)) { item.Message = "Лицето няма електронна поща"; return(false); } if (repo.AllReadonly <ApplicationUser>().Where(x => x.NormalizedEmail == email.ToUpper()).Any()) { item.Message = "Съществуваща електронна поща"; return(false); } } repo.Add(lawUnit); repo.SaveChanges(); //Ако има електронна поща се създава и потребител if (!string.IsNullOrEmpty(email)) { var user = new ApplicationUser { UserName = email, Email = email, LawUnitId = lawUnit.Id, CourtId = item.CourtId, WorkNotificationToMail = true, IsActive = true }; IdentityResult res = null; res = await userManager.CreateAsync(user).ConfigureAwait(false); if (res.Succeeded) { return(true); } else { return(false); } } else { return(true); } } catch (Exception ex) { item.Message = ex.Message; return(false); } }