public async Task <ActionResult <Shipper> > Post([FromBody] Shipper shipper) { try { shipper.ShipperID = Guid.NewGuid(); await shipperRepo.CreateAsync(shipper); return(CreatedAtRoute("GetShipperByID", new { id = shipper.ShipperID }, shipper)); } catch (Exception) { return(BadRequest()); } }
public async Task <bool> Handle(CreateShipperCommand request, CancellationToken cancellationToken) { return(await _shipperRepository.CreateAsync(request)); //var shippingTypes = new List<OnlineShop.Domain.Entities.ShippingType>(); //foreach (var id in request.ShippingTypes) //{ // var sT = await dbContext.ShippingTypes.FindAsync(id); // if(sT != null) // { // shippingTypes.Add(sT); // } //} //var shipper = new OnlineShop.Domain.Entities.Shipper //{ // FirstName = request.FirstName, // LastName = request.LastName, // Address = request.Address, // City = request.City, // State = request.State, // ShippingTypes = shippingTypes //}; //try //{ // await dbContext.Shippers.AddAsync(shipper); // await dbContext.SaveChangesAsync(); // return "Success"; //} //catch (Exception ex) //{ // return ex.Message; //} }