private LawUnit mapLawyer(LawyerModel lawyer, List <CodeMapping> bars) { var model = new LawUnit() { UicTypeId = NomenclatureConstants.UicTypes.EGN, LawUnitTypeId = NomenclatureConstants.LawUnitTypes.Lawyer, Code = lawyer.PersonalId, Department = bars.Where(x => x.OuterCode == lawyer.BarAssociation).Select(x => x.Description).FirstOrDefault(), DateFrom = DefaultDateFrom, DateWrt = DateTime.Now }; if (!lawyer.PracticeAllowed) { model.DateTo = DefaultDateTo; } model.SplitPersonNames(lawyer.Name); model.FullName = model.MakeFullName(); if (!string.IsNullOrEmpty(model.Uic)) { model.Person.CopyFrom(model); } else { model.Person = null; } return(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); } }