public async Task <bool> CreateAsync(CreateShipperCommand req) { var shippingTypes = new List <OnlineShop.Domain.Entities.ShippingType>(); foreach (var id in req.ShippingTypes) { var sT = await _dbContext.ShippingTypes.FindAsync(id); if (sT != null) { shippingTypes.Add(sT); } } var shipper = new OnlineShop.Domain.Entities.Shipper { FirstName = req.FirstName, LastName = req.LastName, Address = req.Address, City = req.City, State = req.State, ShippingTypes = shippingTypes }; try { await _dbContext.Shippers.AddAsync(shipper); var result = await _dbContext.SaveChangesAsync() > 0; if (result) { await _cacheService .DeleteKeyAsync(RedisDefaultKeys.GetAllShippers); } return(result); } catch (Exception ex) { //return ex.Message; return(false); } }
public async Task <IActionResult> CreateShipper([FromBody] CreateShipperCommand command) { var result = await _mediatr.Send(command); return(result ? (IActionResult)Ok() : BadRequest()); }