public async Task <ActionResult <ShipperModel> > AddShipper(ShipperModel shipperModel) { var shipper = _mapper.Map <Shipper>(shipperModel); _shipperService.Add(shipper); if (await _shipperService.IsSavedToDb()) { var persistedShipperModel = _mapper.Map <ShipperModel>(shipper); return(CreatedAtAction(nameof(GetShipper), new { shipperId = persistedShipperModel.ShipperId }, persistedShipperModel)); } return(BadRequest()); }
public ActionResult AddShipper(Shipper model) { if (ModelState.IsValid) { Shipper shipper = new Shipper(); shipper.CompanyName = model.CompanyName; shipper.Phone = model.Phone; try { _shipperService.Add(shipper); return(RedirectToAction("shipperList")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } else { ModelState.AddModelError("", "Girdiğiniz bilgileri kontrol ediniz"); } return(View()); }
public IActionResult SaveEntity(ShipperViewModel viewModel) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(n => n.Errors); return(new BadRequestObjectResult(allErrors)); } else { if (viewModel.Id == 0) { _shipperService.Add(viewModel); } else { _shipperService.Update(viewModel); } } _shipperService.Save(); return(new OkObjectResult(viewModel)); }
public ActionResult Create(Shipper shipper) { _shipperService.Add(shipper); return(RedirectToAction("Index")); }