public static void Initialize(IServiceProvider serviceProvider) { using (var context = new MigrationDbContext(serviceProvider.GetRequiredService <DbContextOptions <MigrationDbContext> >())) { if (context.Blogs.Any()) { return; } context.Blogs.Add(new DataMigrate.Domain.Blog { Id = 1, Url = "blog" }); context.Posts.Add(new DataMigrate.Domain.Post { Id = 1, Title = "post" }); context.Tags.Add(new DataMigrate.Domain.Tag { Id = 1, Name = "tag" }); context.PostTags.Add(new DataMigrate.Domain.PostTag { Id = 1, PostId = 1, TagId = 1 }); context.SaveChanges(); } }
public (Guid organizationId, Guid employeeId, Guid profileId, Guid personId) SaveSignIn(SignInEditModel model, string path) { var organization = new OrganizationExt(); if (!string.IsNullOrEmpty(model.EDRPOU)) { organization = _context.Organizations.FirstOrDefault(x => x.EDRPOU == model.EDRPOU); } else { organization = null; } if (organization == null) { organization = new OrganizationExt { Name = model.Name, EDRPOU = model.EDRPOU, EMail = model.OrgEmail, INN = !string.IsNullOrEmpty(model.EDRPOU) ? null : model.INN }; _context.Add_Auditable(organization); _context.SaveChanges(); var licenses = _limsService.GetLicenses("", !string.IsNullOrEmpty(model.EDRPOU) ? model.EDRPOU : model.INN).Result; var trlLicenseIds = new List <string> { "2", "3", "4" }; var orgInfoPRL = new OrganizationInfo() { Name = model.Name, Type = "PRL", OrganizationId = organization.Id, IsActualInfo = true, IsPendingLicenseUpdate = licenses.Any(x => x.LicenseTypesIds.Contains("1")) }; var orgInfoIML = new OrganizationInfo() { Name = model.Name, Type = "IML", OrganizationId = organization.Id, IsActualInfo = true, IsPendingLicenseUpdate = licenses.FirstOrDefault(x => x.LicenseTypesIds.Contains("5")) != null }; var orgInfoTRL = new OrganizationInfo() { Name = model.Name, Type = "TRL", OrganizationId = organization.Id, IsActualInfo = true, IsPendingLicenseUpdate = licenses.Any(x => x.LicenseTypesIds.Split("|").Any(y => trlLicenseIds.Contains(y))) }; _context.AddRange_Auditable(orgInfoPRL, orgInfoIML, orgInfoTRL); _context.SaveChanges(); //TODO email } var person = _context.Person.FirstOrDefault(x => x.IPN == model.INN && x.LastName == model.LastName); if (person == null) { person = new Person { LastName = model.LastName, MiddleName = model.MiddleName, Name = model.UserName, Phone = model.UserPhone, IPN = model.INN, Email = model.UserEmail, Birthday = DateTime.MinValue, Caption = $"{model.LastName} {model.UserName} {model.MiddleName}" }; _context.Add_Auditable(person); _context.SaveChanges(); } var employees = _context.EmployeesExt.Where(x => x.PersonId == person.Id) .Include(x => x.DefaultValues) .Include(x => x.Profiles) .ToList(); var employeeOrg = employees.FirstOrDefault(x => x.OrganizationId == organization.Id); var profile = _context.Profiles.FirstOrDefault(x => x.Caption == "Employee"); if (employeeOrg != null) { employeeOrg.Position = model.Position; employeeOrg.UserEmail = model.UserEmail; employeeOrg.ReceiveOnChangeAllMessage = model.ReceiveOnChangeAllMessage; employeeOrg.ReceiveOnChangeOwnMessage = model.ReceiveOnChangeOwnMessage; employeeOrg.ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication; employeeOrg.ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication; employeeOrg.PersonalCabinetStatus = model.PersonalCabinetStatus; employeeOrg.ReceiveOnChangeOrgInfo = model.ReceiveOnChangeOrgInfo; employeeOrg.ReceiveOnOverduePayment = model.ReceiveOnOverduePayment; try { if (employeeOrg.DefaultValues.FirstOrDefault()?.ValueId != organization.Id) { employeeOrg.DefaultValues = new List <UserDefaultValue> { new UserDefaultValue { Caption = person.Caption, EntityName = nameof(OrganizationExt), ValueId = organization.Id } }; } } catch (Exception) { if (employeeOrg.DefaultValues.Any()) { employeeOrg.DefaultValues = new List <UserDefaultValue> { new UserDefaultValue { Caption = person.Caption, EntityName = nameof(OrganizationExt), ValueId = organization.Id } }; } } if (employeeOrg.Profiles.Any()) { employeeOrg.Profiles = new List <UserProfile> { new UserProfile { ProfileId = profile.Id, Caption = $"{profile.Caption}: {person.Caption}" } }; } _context.SaveChanges(); if (employeeOrg.UserEmail != model.UserEmail) { //TODO Email } } else { employeeOrg = new EmployeeExt { PersonId = person.Id, Position = model.Position, UserEmail = model.UserEmail, ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication, ReceiveOnChangeAllMessage = model.ReceiveOnChangeAllMessage, ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication, ReceiveOnChangeOwnMessage = model.ReceiveOnChangeOwnMessage, PersonalCabinetStatus = model.PersonalCabinetStatus, ReceiveOnChangeOrgInfo = model.ReceiveOnChangeOrgInfo, ReceiveOnOverduePayment = model.ReceiveOnOverduePayment, OrganizationId = organization.Id, DefaultValues = new List <UserDefaultValue> { new UserDefaultValue { Caption = person.Caption, EntityName = nameof(OrganizationExt), ValueId = organization.Id } }, Profiles = new List <UserProfile> { new UserProfile { ProfileId = profile.Id, Caption = $"{profile.Caption}: {person.Caption}" } } }; _context.Add_Auditable(employeeOrg); _context.SaveChanges(); //TODO Email } return(organization.Id, employeeOrg.Id, profile.Id, person.Id); }