public async Task <ActionResult <bool> > PutRow([FromBody] RowDto row) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } while (_context.Services.Any(u => u.RowId == row.Id)) { _context.Services.Remove(await _context.Services.FirstOrDefaultAsync(u => u.RowId == row.Id)); await _context.SaveChangesAsync(); } _context.Update(RowConverter.RowConvert(row)); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RowExists(row.Id)) { return(NotFound()); } else { throw; } } return(Ok(true)); }
public async Task <IActionResult> AddRowAsync(RowDto row) { Logger.Here().Info("{AddAsyncRow} - {rowId}", nameof(AddRowAsync), row.Id); var result = await _service.CreateInfrastructureService().AddRowAsync(row); return(GetCreatedStatus(result, nameof(GetRowAsync), "Given row is not addable.")); }
public async Task <RowDto> UpdateRowAsync(RowDto rowDto) { ValidateNull(Logger.Here(), rowDto); var row = Map(rowDto); return((await _unitOfWork.RepositoryInfrastructure.UpdateRowAsync(row)) > 0 ? rowDto : null); }
public static Row RowConvert(RowDto item) { var serviceNames = new List <ServiceName>(); if (item.Names != null && item.Names.Count != 0) { foreach (var name in item.Names) { serviceNames.Add(new ServiceName { Name = name }); } } return(new Row { Id = item.Id, Table = item.Table, Type = item.Type, Name = item.Name, Names = serviceNames, Time = item.Time, Sedan = item.Sedan, Universal = item.Universal, Jeep = item.Jeep, Minivan = item.Minivan, Van = item.Van, Pos = item.Pos }); }
public async Task <RowDto> AddRowAsync(RowDto row) { ValidateNull(Logger.Here(), row); var rows = await GetRowsFromCinemaHallAsync(row.CinemaHallId); if (rows.Any(r => r.Number == row.Number)) { var exception = new PersistenceException(nameof(AddRowAsync)); Logger.Error(exception, "{Row} with {number} already exists", row, row.Number); throw exception; } var id = await _unitOfWork.RepositoryInfrastructure.AddRowAsync(Map(row)); row.Id = id; return(row); }
public async Task <ActionResult> UpdateRow(RowDto row) { var infrastructureService = _service.CreateInfrastructureService(); Logger.Here().Info(nameof(UpdateRow)); if (!await infrastructureService.RowExistAsync(row.Id)) { Logger.Here().Error("{UpdateRow} - does not exist", nameof(UpdateRow)); return(BadRequestResponse("Given row category does not exist")); } if (await infrastructureService.UpdateRowAsync(row) != null) { return(UpdatedResponse()); } Logger.Here().Error("{UpdateRow} - is not updateable", nameof(UpdateRow)); return(BadRequestResponse("Given row category is not updateable.")); }
public async Task <ActionResult <Row> > PostRow([FromBody] RowDto row) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } foreach (var r in _context.Rows.ToList()) { if (r.Table == row.Table && r.Pos >= row.Pos) { r.Pos++; } } _context.Rows.Add(RowConverter.RowConvert(row)); await _context.SaveChangesAsync(); return(Ok(row)); }
public async Task Test_Workflow_RowWithoutReservations_Valid() { var cinemaHall = DataSeeder.CinemaHalls.Last().Id; Logger.Info("Load rows ..."); var response = await Get(BaseUrl, $"{EndpointRows}/{cinemaHall}"); await CheckResponseAndLogStatusCodeAsync(Logger, response); var rows = JsonConvert .DeserializeObject <IEnumerable <RowDto> >(await response.Content.ReadAsStringAsync()).ToList(); rows.Should().HaveCount(DataSeeder.Rows.Count(r => r.CinemaHallId == cinemaHall)); Logger.Info(rows.ToPrettyString()); var defaultCategory = DataSeeder.RowCategories.First().Id; var newRow = new RowDto { CategoryId = defaultCategory, CinemaHallId = cinemaHall, Number = 515 }; var updatedRow = rows.First(); updatedRow.Number = 510; var deleteRowReferences = rows .Where(r => r.CinemaHallId == cinemaHall) .First(r => DataSeeder.Seats.Select(s => s.RowId).Contains(r.Id)) .Id; var deletedRow = rows .Where(r => r.CinemaHallId == cinemaHall) .First(r => !DataSeeder.Seats.Select(s => s.RowId).Contains(r.Id)) .Id; await Authenticate(AdminUser, AdminPassword); Logger.Info($"Add new row: {newRow.ToPrettyString()} ..."); response = await Post(BaseUrl, EndpointRow, newRow); await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.Created); var newId = await GetCreatedIdAsync(response); Logger.Info($"Update row: ${updatedRow.ToPrettyString()} ..."); response = await Put(BaseUrl, EndpointRow, updatedRow); await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.NoContent); Logger.Info($"Try delete row with referenced seats: {deleteRowReferences} ..."); response = await Delete(BaseUrl, $"{EndpointRow}/{deleteRowReferences}"); await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.BadRequest); Logger.Info($"Delete row: {deletedRow} ..."); response = await Delete(BaseUrl, $"{EndpointRow}/{deletedRow}"); await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.NoContent); Logger.Info("Load rows ..."); response = await Get(BaseUrl, $"{EndpointRows}/{cinemaHall}"); await CheckResponseAndLogStatusCodeAsync(Logger, response); rows = JsonConvert.DeserializeObject <IEnumerable <RowDto> >(await response.Content.ReadAsStringAsync()) .ToList(); var rowIds = rows.Select(g => g.Id).ToList(); rowIds.Should().Contain(newId); rowIds.Should().Contain(updatedRow.Id); rowIds.Should().Contain(deleteRowReferences); rowIds.Should().NotContain(deletedRow); rows.First(g => g.Id == newId).Number.Should().Be(newRow.Number); rows.First(g => g.Id == updatedRow.Id).Number.Should().Be(updatedRow.Number); Logger.Info(rows.ToPrettyString()); }