public void Create(StopDTO stopDTO) { var stop = Mapper.Map <StopDTO, Stop>(stopDTO); stop.StopNumber = _stopRepository.GetNextStopNumberForStopName(stopDTO.Name); _stopRepository.Add(stop); }
public async Task <IActionResult> CreateStop([FromBody] StopForCreationDTO stopInput) { if (stopInput == null) { return(BadRequest()); } if (stopInput.Name.Equals(stopInput.Description, StringComparison.CurrentCultureIgnoreCase)) { ModelState.AddModelError(nameof(StopForCreationDTO), "Stop name and description must be different!"); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } StopDTO stop = await _stopBus.CreateStop(stopInput); if (stop == null) { return(StatusCode(500, "Insert failure")); } return(CreatedAtRoute("GetStop", new { id = stop.Id }, stop)); }
public LineDTO Correct(LineDTO line) { StopDTO previousStop = null; var stopIndexesToDelete = new List <int>(); int stopIndex = 0; foreach (var stop in line.Stops) { if (previousStop != null && stop.Id == previousStop.Id) { stopIndexesToDelete.Add(stopIndex); } previousStop = stop; stopIndex++; } stopIndexesToDelete.Reverse(); var tempStops = line.Stops.ToList(); foreach (int stopIndexToDelete in stopIndexesToDelete) { tempStops.RemoveAt(stopIndexToDelete); } line.Stops = tempStops; return(line); }
internal static Stop Transform(StopDTO stopDTO) { return(new Stop(LocationsDTOToModel.Transform(stopDTO.Station), (stopDTO.Arrival == null) ? (DateTime?)null : DateTime.Parse(stopDTO.Arrival, null, System.Globalization.DateTimeStyles.RoundtripKind), (stopDTO.Departure == null) ? (DateTime?)null : DateTime.Parse(stopDTO.Departure, null, System.Globalization.DateTimeStyles.RoundtripKind), stopDTO.Platform, stopDTO.Delay)); }
public void Edit(StopDTO stopDTO) { var stop = _stopRepository.Find(stopDTO.Id); int newStationNumber = _stopRepository.GetNextStopNumberForStopName(stopDTO.Name); stop = _stopFactory.FillIn(stop, stopDTO.Name, stopDTO.Latitude, stopDTO.Longitude, stopDTO.StopType, newStationNumber); _stopRepository.Update(stop); }
public async Task <bool> DeleteStop(StopDTO stopModel) { //Stop stop = StopMapper.ConvertModelToEntity(stopModel); if (stopModel != null && await _stopRepo.DeleteStop(stopModel.Id)) { return(true); } return(false); }
public JsonResult GetStop(long id) { StopDTO stop = null; try { stop = _stopManager.GetById(id); } catch (Exception ex) { return(Json(new { error = ex.Message })); } return(Json(stop, JsonRequestBehavior.AllowGet)); }
public IActionResult Put(int id, [FromBody] NewRouteModel newRoute) { RouteDTO routeDTO = new() { DestinationStop = new StopDTO { Id = newRoute.DestinationId }, SourceStop = new StopDTO { Id = newRoute.SourceId }, }; OperationResult result = RouteBDC.Update(id, routeDTO); return(this.GetResponse(result)); }
public OperationResult Add(StopDTO stopDTO) { OperationResult result = new(); try { Stop stop = new() { Name = stopDTO.Name }; UnitOfWork.Stops.Add(stop); UnitOfWork.Complete(); } catch (Exception e) { result.SetExceptionResult(e.StackTrace); } return(result); }
public async Task <IActionResult> DeleteStop(int id) { StopDTO stop = await _stopBus.GetStop(id); if (stop == null) { return(NotFound()); } if (!await _stopBus.DeleteStop(stop)) { return(StatusCode(500, "Delete failure")); } _logger.LogInformation(1, $"Stop with id={id}and name={stop.Name} deleted"); return(NoContent()); }
public async Task <IHttpActionResult> PostStop(Stop stop) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Stop.Add(stop); await db.SaveChangesAsync(); db.Entry(stop).Reference(x => x.Bus).Load(); var dto = new StopDTO() { Id = stop.ID, Name = stop.Name, }; return(CreatedAtRoute("DefaultApi", new { id = stop.ID }, dto)); }
public async Task <IActionResult> UpdateStop(int id, [FromBody] StopForUpdateDTO stopInput) { if (stopInput == null) { return(BadRequest()); } if (stopInput.Latitude > 360 || stopInput.Longitude > 360) { ModelState.AddModelError(nameof(StopForUpdateDTO), "Latitude and longitude can be specified up to 360 degrees"); } if (string.IsNullOrWhiteSpace(stopInput.Name)) { ModelState.AddModelError(nameof(StopForUpdateDTO), "Empty name is invalid!"); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var stopResult = await _stopBus.UpdateStop(id, stopInput); if (stopResult == null || stopResult.Result == null) { return(StatusCode(500, "Update failure")); } StopDTO stop = stopResult.Result as StopDTO; if (stopResult.StatusCode == 201) { return(CreatedAtRoute("GetStop", new { id = stop.Id }, stop)); } return(NoContent()); }
public async Task <IActionResult> Get([FromRoute] int id, [FromQuery] string fields) { if (!_typeHelperService.TypeHasProperties <StopDTO>(fields)) { return(BadRequest()); } StopDTO stop = await _stopBus.GetStop(id); if (stop == null) { return(NotFound()); } var links = CreateLinksForStop(id, fields); var linkedResourceToReturn = stop.ShapeData(fields) as IDictionary <string, object>; linkedResourceToReturn.Add("links", links); return(Ok(linkedResourceToReturn)); }
public OperationResult Update(int stopId, StopDTO stopDTO) { OperationResult result = new(); try { Stop stopInDb = UnitOfWork.Stops.Get(stopId); if (stopInDb != null) { Mapper.Map <StopDTO, Stop>(stopDTO, stopInDb); UnitOfWork.Complete(); result.SetSuccessResult(); } else { result.SetFailureResult("No stop with this id"); } } catch (Exception e) { result.SetExceptionResult(e.StackTrace); } return(result); }
public OperationResult <StopDTO> Get(int stopId) { OperationResult <StopDTO> result = new(); try { Stop stopInDb = UnitOfWork.Stops.Get(stopId); StopDTO stopDTO = null; if (stopInDb != null) { stopDTO = Mapper.Map <Stop, StopDTO>(stopInDb); result.SetSuccessResult(stopDTO); } else { result.SetFailureResult("No Stop with this id."); } } catch (Exception e) { result.SetExceptionResult(e.StackTrace); } return(result); }
public static Stop ConvertModelToEntity(StopDTO stopModel) { return(AutoMapperContainer.GenericConvert <Stop>(stopModel)); }
public void Remove(StopDTO stopDTO) { var stop = _stopRepository.Find(stopDTO.Id); _stopRepository.Remove(stop); }