public async Task <ActionResult> Create([FromBody] CreateSellerContactDTO sellerContactDTO) { SellerContact sellerContact = _mapper.Map <SellerContact>(sellerContactDTO); await _sellerContactRepository.CreateAsync(sellerContact); return(CreatedAtRoute("GetSellerContactById", new { sellerContact.Id }, sellerContact)); }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { ISellerRepository sellerRepository = (ISellerRepository)context.HttpContext.RequestServices.GetService(typeof(ISellerRepository)); CreateSellerContactDTO sellerContactDTO = (CreateSellerContactDTO)context.ActionArguments["sellerContactDTO"]; if (!await sellerRepository.ExistsAsync(sellerContactDTO.SellerId)) { context.ModelState.AddModelError("SellerId", "The given seller id does not correspond to an existing seller"); } await next(); }