Exemplo n.º 1
0
        public async Task <ActionResult <ShipperAPIModel> > UpdateShipper(int id, ShipperAPIModel shipper)
        {
            var validator        = new ShipperValidator();
            var validationResult = await validator.ValidateAsync(shipper);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var shipperToUpdate = await _shipperService.GetShipperById(id);

            if (shipperToUpdate == null)
            {
                return(NotFound());
            }

            var shipperModel = _mapper.Map <ShipperAPIModel, Shippers>(shipper);

            await _shipperService.UpdateShipper(shipperToUpdate, shipperModel);

            shipperModel = await _shipperService.GetShipperById(id);

            var shipperAPIModel = _mapper.Map <Shippers, ShipperAPIModel>(shipperModel);

            return(Ok(shipperAPIModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Put(int id, [FromBody] ShipperModel Model)
        {
            Model.ShipperID = id;
            var result = await _shippderService.UpdateShipper(Model);

            if (result > 0)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 3
0
        public async Task TestMethod_測試UpdateShipper()
        {
            var ShipperID = await GetMaxId();

            var RandomTel = DateTime.Now.ToString("hhmmss");
            var Shipper   = new ShipperModel {
                ShipperID = ShipperID, CompanyName = "Fragile", Phone = RandomTel
            };

            var result = await shipperService.UpdateShipper(Shipper);

            var GetResult = await shipperService.GetShipperByID(ShipperID);

            Assert.AreEqual(GetResult.FirstOrDefault().Phone, RandomTel);
        }
Exemplo n.º 4
0
        public ActionResult UpdateShipper(ShipperVM model)
        {
            var _shipper = _shipperService.GetShipper(model.Id);

            if (_shipper == null)
            {
                return(NotFound());
            }
            if (_shipperService.GetShippers(s => s.Phone == model.Phone).Count() > 0)
            {
                return(BadRequest("Phone Number Has Been Exist"));
            }
            Shipper newShipper = model.Adapt(_shipper);

            _shipperService.UpdateShipper(newShipper);
            _shipperService.Save();
            return(Ok(201));
        }
Exemplo n.º 5
0
 public void Put(ShipperViewModel shipper)
 {
     _shipperService.UpdateShipper(shipper);
 }