public async Task <GetProductOutput> Create(CreateProductInput input) { var product = input.MapTo <Product>(); product = await _productDomainService.Create(product); return(product.MapTo <GetProductOutput>()); }
public async Task Handle(CreateProductCommand message) { _authorizationService.CheckPermission("User.CreateProduct"); message.Validate(); using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin(IsolationLevel.ReadCommitted)) { await _productDomainService.Create(message.Name, message.Code, message.Barcode); await unitOfWork.Complete(); } await _mailSender.Send($"Hello {_session.Username}, product is created for you.", "Product Creation", _session.Email); await _realtimeNotifier.Notify("ProductCreated", message.ToString()); }
public async Task <IActionResult> Create([FromBody] ProductCreateViewModel data) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _domainService.Create(data.Name, data.Description, data.Price); return(Ok("Product created.")); } catch { return(BadRequest()); } }