public void OpenOrganization(OpenOrganizationRequestVm model) { if (model == null) { throw new ArgumentNullException($"{typeof(OpenOrganizationRequestVm).Name} is null"); } var checkOrganization = /*(from o in _aplicationDbContext.Organizations * where o.IdentificationNumber == model.IdentificationNumber || * o.FullName == model.FullName * select o).ToList(); */ _aplicationDbContext.Organizations .SingleOrDefault(p => p.IdentificationNumber == model.IdentificationNumber || p.FullName == model.FullName); var checkOrganizationType = _aplicationDbContext.OrganizationTypes .SingleOrDefault(p => p.Name == model.OrganizationType); if (checkOrganization != null || checkOrganizationType == null) { throw new Exception("Model validation error!"); } var organization = Mapper.Map <Organization>(model); organization.OrganizationType = checkOrganizationType; organization.RegistrationDate = DateTime.Now; _aplicationDbContext.Organizations.Add(organization); _aplicationDbContext.SaveChanges(); }
//добавить орагинизвцию public int OpenOrganization(OpenOrganizationRequestVm model) { if (model == null) { throw new ArgumentNullException($"{typeof(OpenOrganizationRequestVm).Name} is null"); } var checkOrganization = _aplicationDbContext.Organizations .SingleOrDefault(p => p.IdentificationNumber == model.IdentificationNumber || p.FullName == model.FullName); var checkOrganizationType = _aplicationDbContext.OrganizationTypes .SingleOrDefault(p => p.Name == model.OrganizationType); if (checkOrganization != null || checkOrganizationType == null) { throw new Exception("Model validation error!"); } Organization organization = new Organization() { FullName = model.FullName, IdentificationNumber = model.IdentificationNumber, OrganizationType = checkOrganizationType, RegistrationDate = DateTime.Now, Email = model.Email, PhoneNumber = model.PhoneNumber, Adress = model.Adress, LinkToSite = model.LinkToSite }; _aplicationDbContext.Organizations.Add(organization); _aplicationDbContext.SaveChanges(); return(organization.Id); }
public static void CreateOrganization() { OrganizationManagementService organizationService = new OrganizationManagementService(); OpenOrganizationRequestVm openOrganization = new OpenOrganizationRequestVm() { FullName = "TestOrganization", IdentificationNumber = "1111-2222-3333", OrganizationType = "TOO" }; organizationService.OpenOrganization(openOrganization); }
public static int CreateOrganization() { OrganizationManagementService organizationService = new OrganizationManagementService(); OpenOrganizationRequestVm openOrganization = new OpenOrganizationRequestVm() { FullName = "TestOrganization", IdentificationNumber = "1111-2222-3333", OrganizationType = "TOO", Adress = "testAdress", PhoneNumber = "870000000", Email = "test", LinkToSite = "LINK" }; return(organizationService.OpenOrganization(openOrganization)); }
public void OpenOrganization(OpenOrganizationRequestVm model) { if (model == null) { throw new ArgumentNullException($"{typeof(OpenOrganizationRequestVm).Name} is null"); } var checkOrganization = /*(from o in _aplicationDbContext.Organizations * where o.IdentificationNumber == model.IdentificationNumber || * o.FullName == model.FullName * select o).ToList(); */ _aplicationDbContext.Organizations .SingleOrDefault(p => p.IdentificationNumber == model.IdentificationNumber || p.FullName == model.FullName); if (checkOrganization != null) { throw new Exception("Такая организация уже существует в базе"); } var checkOrganizationType = _aplicationDbContext.OrganizationTypes .SingleOrDefault(p => p.Name == model.OrganizationType); if (checkOrganizationType == null) { throw new Exception("Организационно-правовая форма организации не корректна"); } var Position = _aplicationDbContext.EmployeePositions.SingleOrDefault(p => p.PositionName == "Director"); if (Position == null) { throw new Exception("Данной должности не имеется в списке должностей"); } var UserExists = _identityDbContext.ApplicationUsers.SingleOrDefault(p => p.Email == model.DirectorEmail); if (UserExists != null) { throw new Exception("Пользователь с данным мэйлом уже существует"); } Organization organization = new Organization() { FullName = model.FullName, IdentificationNumber = model.IdentificationNumber, RegistrationDate = DateTime.Now, OrganizationTypeId = checkOrganizationType.Id, OrganizationEmail = model.OrganizationEmail, PhoneNumber = model.PhoneNumber, LinkToWebsite = model.LinkToWebsite, Address = model.Address, }; _aplicationDbContext.Organizations.Add(organization); _aplicationDbContext.SaveChanges(); Employee employee = new Employee() { FirstName = model.DirectorFirstName, LastName = model.DirectorLastName, DoB = model.DirectorDoB, Email = model.DirectorEmail, EmployeePositionId = Position.Id, OrganizationId = organization.Id }; _aplicationDbContext.Employees.Add(employee); _aplicationDbContext.SaveChanges(); ApplicationUser user = new ApplicationUser() { Email = model.DirectorEmail, IsActive = true, FailedSignInCount = 0, CreatedDate = DateTime.Now, AssosiatedEmployeeId = employee.Id }; _identityDbContext.ApplicationUsers.Add(user); _identityDbContext.SaveChanges(); ApplicationUserPasswordHistory userPasswordHistory = new ApplicationUserPasswordHistory() { SetupDate = DateTime.Now, InvalidatedDate = DateTime.Now.AddMonths(3), Password = model.Password, ApplicationUserId = user.Id }; _identityDbContext.ApplicationUserPasswordHistories.Add(userPasswordHistory); _identityDbContext.SaveChanges(); var geoLocationInfo = GeoLocationInfo.GetGeolocationInfo(); ApplicationUserSignInHistory userSignInHistory = new ApplicationUserSignInHistory() { SignInTime = DateTime.Now, MachineIp = geoLocationInfo.ip, IpToGeoCountry = geoLocationInfo.country_name, IpToGeoCity = geoLocationInfo.city, IpToGeoLatitude = geoLocationInfo.latitude, IpToGeoLongitude = geoLocationInfo.longitude, ApplicationUserId = user.Id }; _identityDbContext.ApplicationUserSignInHistories.Add(userSignInHistory); _identityDbContext.SaveChanges(); }