private bool migrate_Institution(MigrationData item) { var data = item.Data.Split('|'); try { int institutionTypeId = int.Parse(item.DataType.Substring(12)); var model = new Institution() { Person = null, InstitutionTypeId = institutionTypeId, UicTypeId = NomenclatureConstants.UicTypes.EGN, FirstName = data[0], MiddleName = data[1], FamilyName = data[2], Family2Name = data[3], Code = data[4] }; if (!string.IsNullOrEmpty(item.Code)) { model.Uic = item.Code; } if (!string.IsNullOrEmpty(model.Code)) { var savedInst = repo.AllReadonly <Institution>() .Where(x => x.Code == model.Code && x.InstitutionTypeId == model.InstitutionTypeId) .FirstOrDefault(); if (savedInst != null) { item.Message = $"{savedInst.Code} {savedInst.FullName} вече съществува"; return(false); } } if (!string.IsNullOrEmpty(model.Uic)) { var savedInst = repo.AllReadonly <Institution>() .Where(x => x.Uic == model.Uic && x.UicTypeId == model.UicTypeId && x.InstitutionTypeId == model.InstitutionTypeId) .FirstOrDefault(); if (savedInst != null) { item.Message = $"{savedInst.Uic} {savedInst.FullName} вече съществува"; return(false); } } switch (institutionTypeId) { case NomenclatureConstants.InstitutionTypes.Notary: model.DepartmentName = data[5].Trim(); break; default: break; } model.FullName = model.MakeFullName(); repo.Add(model); repo.SaveChanges(); return(true); } catch (Exception ex) { item.Message = ex.Message; return(false); } }