public static void ValidatorAddOfficeIfDtoIsNull(OfficeDto dto) { if (dto.Street == null || dto.StreetNumber <= 0) { throw new OfficeException("Incorrect office data!"); } }
public OfficeDto EditOffice(OfficeDto officeDto) { if ( _dbContext.Offices.Any( x => x.OfficeName.ToLower() == officeDto.OfficeName.ToLower() && x.Location.ToLower() == officeDto.Location.ToLower() && x.Id != officeDto.OfficeId)) { throw new Exception("Already Existing"); } var office = _dbContext.Offices.FirstOrDefault(x => x.Id == officeDto.OfficeId); if (office == null) { throw new Exception("Data not Found"); } office.OfficeName = officeDto.OfficeName; office.Location = officeDto.Location; _dbContext.SaveChanges(); officeDto.OfficeId = office.Id; return(officeDto); }
public static OfficeDto ExtractDto(this OfficeLocation officeLocation) { if (officeLocation == null) { return(null); } var officeDto = new OfficeDto() { OfficeId = officeLocation.OfficeId, Name = officeLocation.Name, Address = officeLocation.Address, CountrySlug = officeLocation.Country.Slug, Switchboard = officeLocation.Switchboard, Fax = officeLocation.Fax, }; switch (officeLocation.Operating) { case "Active": officeDto.Operating = 1; break; case "Closed": officeDto.Operating = 0; break; default: throw new ArgumentOutOfRangeException(); } return(officeDto); }
public static void MappOfficeDto(this Office office, OfficeDto officeDto) { //office.Id = officeDto.Id; //office.TenantId = officeDto.TenantId; office.OfficeCode = officeDto.OfficeCode; office.OfficeName = officeDto.OfficeName; office.NickName = officeDto.NickName; office.RegistrationDate = officeDto.RegistrationDate; office.CurrencyCode = officeDto.CurrencyCode; office.PoBox = officeDto.PoBox; office.AddressLine1 = officeDto.AddressLine1; office.AddressLine2 = officeDto.AddressLine2; office.Street = officeDto.Street; office.State = officeDto.State; office.City = officeDto.City; office.ZipCode = officeDto.ZipCode; office.Country = officeDto.Country; office.Phone = officeDto.Phone; office.Fax = officeDto.Fax; office.Email = officeDto.Email; office.Url = officeDto.Url; office.Logo = officeDto.Logo; office.ParentOfficeId = officeDto.ParentOfficeId; office.RegistrationNumber = officeDto.RegistrationNumber; office.PanNumber = officeDto.PanNumber; office.AllowTransactionPosting = officeDto.AllowTransactionPosting; office.CreatedByUserId = officeDto.CreatedByUserId; office.CreatedOn = officeDto.CreatedOn; office.UpdatedByUserId = officeDto.UpdatedByUserId; office.UpdatedOn = officeDto.UpdatedOn; }
public int Insert(OfficeDto dto) { const string sql = @" Insert Into [OfficeLocation].[Office] ( [Name] ,[Address] ,[CountrySlug] ,[Switchboard] ,[Fax] ,[Operating]) Values ( @Name ,@Address ,@CountrySlug ,@Switchboard ,@Fax ,@Operating) SELECT CAST(SCOPE_IDENTITY() as int) "; int newId = 0; ConnectionExecuteWithLog( connection => { newId = connection.Query <int>(sql, dto).Single(); }, sql, dto); return(newId); }
//public void OnAuthorization(AuthorizationFilterContext context) //{ // var sub = context.HttpContext.User.Claims.FirstOrDefault(c => "sub".Equals(c.Type)); // var request = context.ActionDescriptor.Parameters; // if (sub is null) // { // context.Result = new ForbidResult(); // } //} public void OnActionExecuting(ActionExecutingContext context) { // do something before the action executes var sub = context.HttpContext.User.Claims.FirstOrDefault(c => "sub".Equals(c.Type)); var email = context.HttpContext.User.Claims.FirstOrDefault(c => "email".Equals(c.Type)).Value; context.ActionArguments.TryGetValue("tenantId", out object tenantId); context.ActionArguments.TryGetValue("officeId", out object officeId); context.HttpContext.Request.Headers.TryGetValue("User-Agent", out StringValues browser); var request = context.HttpContext.Request.Path; if (sub == null) { context.Result = new ForbidResult(); } if (email == null) { context.Result = new ForbidResult(); } UserDto currentUser = null; TenantDto currentTenant = null; OfficeDto currentOffice = null; RoleDto currentRole = null; var user = _userService.GetUserByEmail(email).Result; if (user == null) { currentUser = _userService.CreateInitialUser(new UserDto { Email = email, Name = email, LastSeenOn = DateTime.Now, LastBrowser = browser, LastIp = context.HttpContext.Connection.RemoteIpAddress.ToString() }).Result; } else { user.LastBrowser = browser; user.LastIp = context.HttpContext.Connection.RemoteIpAddress.ToString(); user.LastSeenOn = DateTime.Now; currentUser = _userService.UpdateContextUser(user).Result; } if (tenantId != null) { currentTenant = _userService.GetTenant(tenantId.ToString()).Result; } if (officeId != null) { currentOffice = currentUser.Offices.FirstOrDefault(o => o.Id == Guid.Parse(officeId.ToString())); } if (currentTenant == null && currentOffice != null) { currentTenant = _userService.GetTenant(currentOffice.TenantId.ToString()).Result; } if (currentOffice != null) { currentRole = currentUser.Roles.FirstOrDefault(r => r.OfficeId == currentOffice.Id); } _authContext.CurrentUser = currentUser; _authContext.CurrentTenant = currentTenant; _authContext.CurrentOffice = currentOffice; _authContext.CurrentRole = currentRole; }
public void ShouldUpdateNewOfficeWithNewInfo() { var testHelper = new TestHelper(); testHelper.DatabaseDataDeleter(() => { var officeDto0 = new OfficeDto() { Name = "Austin", Address = "Dimensional Place 6300 Bee Cave Road", CountrySlug = "C1", Switchboard = "***REMOVED***", Fax = "+***REMOVED***", Operating = 1 }; var expectedOfficeId = testHelper.InsertOfficeDto(officeDto0); var updatedOfficeDto = SimulateUpdatingOfficeLocation(expectedOfficeId); var userWrapper = testHelper.GetUserWrapper(); userWrapper.MakeUserPartOfGroup(userWrapper.GroupNameConstants.AdminGroup); var controller = testHelper.CreateController(); var updatedCountry = testHelper.GetCountryRepository().GetCountryBySlug(updatedOfficeDto.CountrySlug); var locationModel = new WebOfficeLocation(updatedOfficeDto, updatedCountry); locationModel.HasChanged = "True"; var locationOffice = new OfficeModel() { NewOffice = locationModel }; locationOffice.NewOffice.HasChanged = "true"; var actionResult = controller.Save(locationOffice); var officeLocationRepository = testHelper.GetOfficeLocationRepository(); var offices = officeLocationRepository.GetAll(); //*************************** offices.Length.Should().Be(1); offices[0].OfficeId.Should().Be(expectedOfficeId); offices[0].Name.Should().Be("Changed"); offices[0].Address.Should().Be("Updated"); offices[0].Country.Name.Should().Be("Country 1"); offices[0].Country.Slug.Should().Be("C1"); offices[0].Switchboard.Should().Be("Different value here"); offices[0].Fax.Should().Be("This had changed"); offices[0].Operating.Should().Be("Closed"); }); }
private async Task <OfficeViewModel> GetOfficeViewModelAsync(OfficeDto office) { var officeViewModel = new OfficeViewModel { Id = office.Id, Street = office.Street, StreetNumber = office.StreetNumber, CompanyId = office.CompanyId, CountryId = office.CountryId, CityId = office.CityId, AllCompanies = (await this.companyService.GetAllAsync()).Select(company => new CompanyViewModel { Id = company.Id, Name = company.Name, CreationDate = company.CreationDate }), AllCountries = (await this.countryService.GetAllAsync()).Select(country => new CountryViewModel { Id = country.Id, Name = country.Name, }), CitiesByCountry = office.CountryId == 0 ? Enumerable.Empty <CityViewModel>() : (await this.cityService.GetAllByCountryIdAsync(office.CountryId)) .Select(country => new CityViewModel { Id = country.Id, Name = country.Name, }), }; return(officeViewModel); }
public OfficeLocation GetById(int id) { OfficeDto officeDto = _officeDataTableGateway.GetById(id); var country = _countryRepository.GetCountryBySlug(officeDto.CountrySlug); return(new OfficeLocation(officeDto, country)); }
public async Task DeleteAsync(OfficeDto officeDto) { var office = mapper.Map <Office>(officeDto); context.Offices.Remove(office); await context.SaveChangesAsync(); }
public static OfficeViewModel Create(OfficeDto office, string returnUrl) { return(new OfficeViewModel { Office = office, ReturnUrl = returnUrl }); }
public static Office ToOfficeResource(this OfficeDto dto) { return(new Office { Id = dto.Id, Name = dto.Name }); }
public static bool ValidatorForUpdateOfficeStreet(OfficeDto dto) { if (dto.Street == null) { return(false); } return(true); }
public static bool ValidatorForUpdateOfficeStreetNumber(OfficeDto dto) { if (dto.StreetNumber <= 0) { return(false); } return(true); }
public async Task <OfficeDto> CreateAsync(OfficeDto officeDto) { var office = mapper.Map <Office>(officeDto); await context.Offices.AddAsync(office); await context.SaveChangesAsync(); return(officeDto); }
public IActionResult Delete(int?id) { OfficeDto output = null; if (id.HasValue) { output = _officeAppService.GetById(id.Value); } return(View(output)); }
public async Task DeleteAsync(OfficeDto dto) { var office = await this.context.Offices .Include(empl => empl.Employees) .Where(id => id.Id == dto.Id) .FirstAsync(); office.IsDeleted = true; await this.context.SaveChangesAsync(); }
public OfficeDto Add([FromBody] OfficeDto officeDto) { Office office = officeDtoToOfficeMapping.Map(officeDto); dbContext.Set <Office>() .Add(office); dbContext.SaveChanges(); return(officeToOfficeDtoMapping.Map(office)); }
public static OfficeViewModel Edit(OfficeDto office, string returnUrl) { return(new OfficeViewModel { Office = office, Theme = "warning", Action = "Edit", ShowCreateNewAction = true, ReturnUrl = returnUrl }); }
public static OfficeViewModel Delete(OfficeDto office, string returnUrl) { return(new OfficeViewModel { Office = office, Action = "Delete", ReadOnly = true, Theme = "danger", ReturnUrl = returnUrl }); }
public static OfficeViewModel Details(OfficeDto office, string returnUrl) { return(new OfficeViewModel { Office = office, Action = "Details", ReadOnly = true, Theme = "info", ShowAction = false, ReturnUrl = returnUrl }); }
public async Task <OfficeDto> UpdateOffice(int id, OfficeDto office) { var dbOffice = await _context.Offices.FindAsync(id); dbOffice.Name = office.Name; dbOffice.Adress = office.Adress; dbOffice.SwishNumber = office.SwishNumber; dbOffice.Info = office.Info; await _context.SaveChangesAsync(); return(OfficeTranslator.ToOfficeDto(dbOffice)); }
public ActionResult AddOffice(OfficeDto office) { try { var addedoffice = new OfficeCommands().AddOffice(office); return(RedirectToAction("OfficeEditor", new { id = addedoffice.OfficeId })); } catch (Exception ex) { TempData["Error"] = ex.GetBaseException(); return(RedirectToAction("OfficeEditor")); } }
public OfficeDto Update(int id, [FromBody] OfficeDto officeDto) { Office office = officeDtoToOfficeMapping.Map(officeDto); Office actualOffice = dbContext.Offices .SingleOrDefault(f => f.Id == id); officeUpdater.Update(actualOffice, office); dbContext.SaveChanges(); return(officeToOfficeDtoMapping.Map(actualOffice)); }
public ActionResult EditOffice(OfficeDto office) { try { var editedOffice = new OfficeCommands().EditOffice(office); return(RedirectToAction("OfficeEditor", new { edit = true, officeId = editedOffice.OfficeId })); } catch (Exception ex) { TempData["Error"] = ex.GetBaseException(); return(RedirectToAction("OfficeEditor")); } }
private async void ValidateOffice(OfficeDto officeDto) { // make sure that the Tenant of the officeDto.TenantId is there; if (officeDto.TenantId == null) { throw new Exception($" TenantId is required."); } var tenant = await _tenantRepository.GetByIdAsync(officeDto.TenantId); if (tenant == null) { throw new Exception($" office should be added to an existing Tenant."); } }
public async Task DeleteOffice(OfficeDto office) { using (var httpClient = new HttpClient()) { using (var response = await httpClient.DeleteAsync(uri.AbsoluteUri + office.Id)) { if (!response.IsSuccessStatusCode) { //string apiResponse = await response.Content.ReadAsStringAsync(); throw new Exception(); } } } }
public ActionResult OfficeEditor(int?id) { var model = new OfficeDto(); if (!id.HasValue) { model = new OfficeDto(); } else { model = new OfficeQueries().GetSelectedOffice(id.Value); } return(View(model)); }
public async Task <OfficeDto> CreateOffice(OfficeDto office) { var newOffice = new Office() { Name = office.Name, Adress = office.Adress, SwishNumber = office.SwishNumber }; _context.Offices.Add(newOffice); await _context.SaveChangesAsync(); return(OfficeTranslator.ToOfficeDto(newOffice)); }
public async Task UpdateOffice(OfficeDto office) { using (var httpClient = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(office), Encoding.UTF8, "application/json"); using (var response = await httpClient.PutAsync(uri.AbsoluteUri + office.Id, content)) { if (!response.IsSuccessStatusCode) { throw new Exception(); } } } }