Пример #1
0
        public async Task <RouteDto> UpdateAsync(UpdateRouteDto updateRouteDto)
        {
            var tripEntity = await _tripFlipDbContext
                             .Trips
                             .Where(trip => trip.Id == updateRouteDto.TripId)
                             .Include(trip => trip.Routes)
                             .FirstOrDefaultAsync();

            EntityValidationHelper
            .ValidateEntityNotNull(tripEntity, ErrorConstants.TripNotFound);

            await EntityValidationHelper.ValidateCurrentUserTripRoleAsync(
                _currentUserService,
                _tripFlipDbContext,
                updateRouteDto.TripId,
                TripRoles.Editor,
                ErrorConstants.NotTripEditor);

            var routeEntity = tripEntity
                              .Routes
                              .FirstOrDefault(route => route.Id == updateRouteDto.Id);

            EntityValidationHelper
            .ValidateEntityNotNull(routeEntity, ErrorConstants.RouteNotFound);

            routeEntity.Title  = updateRouteDto.Title;
            routeEntity.TripId = updateRouteDto.TripId;

            await _tripFlipDbContext.SaveChangesAsync();

            var routeDto = _mapper.Map <RouteDto>(routeEntity);

            return(routeDto);
        }
Пример #2
0
 public IActionResult Put(int routeId, [FromBody] UpdateRouteDto updateRouteDto)
 {
     //try
     {
         var updateRoute = this._Mapper.Map <UpdateRouteDto, Route>(updateRouteDto);
         updateRoute.ID = routeId;
         if (this._RouteRepository.SaveRoute(updateRoute) > 0)
         {
             return(Ok(
                        this._Mapper.Map <Route, ReturnRouteDto>(updateRoute)
                        ));
         }
         else
         {
             return(BadRequest(new BadRequestMessage
             {
                 Message = new string[] {
                     "Route fails to update.",
                     "ID does not exist"
                 }
             }));
         }
     }
     //catch (Exception)
     //{
     //    return StatusCode(500, "Internal server error");
     //}
 }
Пример #3
0
 public IHttpActionResult UpdateAdminRoute(int routeId, UpdateRouteDto route)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(Messages.ProcessingError));
     }
     try
     {
         if (User.Identity.IsAuthenticated)
         {
             var destination = _context.Routes.Find(routeId);
             if (destination == null)
             {
                 return(NotFound());
             }
             Mapper.Map(route, destination);
             destination.AppUserId = User.Identity.GetUserId();
             destination.CreatedAt = DateTime.Now;
             _uow.Complete();
             return(Ok(Messages.EntityUpdationSuccess(EntityName)));
         }
         else
         {
             return(BadRequest(Messages.AuthenticationRequired));
         }
     }
     catch (Exception)
     {
         return(BadRequest(Messages.ProcessingError));
     }
 }