Ejemplo n.º 1
0
 public IActionResult Put(int busId, [FromBody] UpdateBusDto updateBusDto)
 {
     try
     {
         var updateBus = this._Mapper.Map <UpdateBusDto, Bus>(updateBusDto);
         updateBus.ID = busId;
         if (this._BusRepository.SaveBus(updateBus) > 0)
         {
             return(Ok(
                        this._Mapper.Map <Bus, ReturnBusDto>(
                            this._BusRepository.Busses.Where(o => o.ID == updateBus.ID).First()
                            )
                        ));
         }
         return(BadRequest(new BadRequestMessage
         {
             Message = new string[] {
                 "Bus fails to update.",
                 "Tip: RegistrationNumber is already exists",
                 "ID of bus does not exist",
                 "ID of busmodel does not exist"
             }
         }));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Internal server error"));
     }
 }
Ejemplo n.º 2
0
        public async Task <BusDto> UpdateAsync(UpdateBusDto updateBusDto)
        {
            using (UnitOfWork)
            {
                var bus = await _busRepository.GetAsync(updateBusDto.Id);

                bus.SetSeatCount(updateBusDto.SeatCount);
                bus.SetRoute(updateBusDto.Route);
                bus.SetMark(updateBusDto.Mark);
                bus.SetExpeditionNumber(updateBusDto.ExpeditionNumber);

                await _busRepository.UpdateAsync(bus);

                await UnitOfWork.SaveChangesAsync();

                return(ObjectMapper.Map <Bus, BusDto>(bus));
            }
        }
Ejemplo n.º 3
0
        public void UpdateBus()
        {
            var target = new BussesController(this._EFBusRepository, this._MockMapper);

            var newBus = new UpdateBusDto
            {
                RegistrationNumber = "UpdateTEST123",
                CapacityBoundary   = 1,
                SeatingPlace       = 2,
                StandingPlace      = 2,
                BusModelID         = 4
            };

            var okResult = target.Put(13, newBus) as OkObjectResult;
            var bus      = (ReturnBusDto)okResult.Value;

            Assert.Equal(200, okResult.StatusCode);
            Assert.Equal("UpdateTEST123", bus.RegistrationNumber.ToString());
            Assert.Equal(1, bus.CapacityBoundary);
        }
Ejemplo n.º 4
0
        public IHttpActionResult UpdateAdminBus(int busId, UpdateBusDto bus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(Messages.ProcessingError));
            }

            if (User.Identity.IsAuthenticated)
            {
                try
                {
                    var busIndDb = _context.Busses.Find(busId);
                    bus.DriverId = bus.DriverId < 0 ? null : bus.DriverId;
                    var driver = _context.Drivers.FirstOrDefault(d => d.DriverId == bus.DriverId && d.AssignedBus == false);

                    if (busIndDb == null)
                    {
                        return(NotFound());
                    }
                    Mapper.Map(bus, busIndDb);
                    busIndDb.CreatedAt = DateTime.Now;
                    busIndDb.AppUserId = User.Identity.GetUserId();
                    if (driver != null)
                    {
                        driver.AssignedBus = true;
                    }
                    _uow.Complete();
                    return(Ok(Messages.EntityUpdationSuccess(EntityName)));
                }
                catch (Exception)
                {
                    return(BadRequest(Messages.EntityCreationError(EntityName)));
                }
            }
            else
            {
                return(BadRequest(Messages.AuthenticationRequired));
            }
        }