public async Task <JsonResult> AddPublisher(Publisher publisher) { var task = Task.Run(() => _publisherServices.CreateAsync(publisher)); var quoteId = await task; return(Json(quoteId, JsonRequestBehavior.AllowGet)); }
public void CreateAsync_CallsService_Always() { var viewModel = GetModifyPublisherViewModel(); _apiPublisherController.CreateAsync(viewModel); A.CallTo(() => _publisherServices.CreateAsync(A <ModifyPublisherDto> ._)).MustHaveHappenedOnceExactly(); }
public async Task <IActionResult> CreateAsync(ModifyPublisherViewModel viewModel) { viewModel.Id = Guid.NewGuid().ToString(); var dto = _mapper.Map <ModifyPublisherDto>(viewModel); await _publisherServices.CreateAsync(dto); _logger.LogDebug($"Create new publisher with name {viewModel.CompanyName}"); return(CreatedAtAction(nameof(GetByIdAsync), new { id = viewModel.Id }, viewModel)); }
public async Task <ActionResult> Create(CreatePublisherInput input) { try { await _publisherService.CreateAsync(input); return(Ok()); } catch (Exception ex) { return(NotFound(ex)); } }
public async Task <IActionResult> CreateAsync(ModifyPublisherViewModel viewModel) { if (!ModelState.IsValid) { return(View("Create", viewModel)); } var dto = _mapper.Map <ModifyPublisherDto>(viewModel); await _publisherServices.CreateAsync(dto); _logger.LogDebug($"Create new publisher with name {viewModel.CompanyName}"); return(RedirectToAction(nameof(GetAllAsync))); }
public async Task <HttpResponseMessage> Add([FromBody] PublisherCreateModel model) { HttpResponseMessage returnMessage = new HttpResponseMessage(); var role = mapper.Map <PublisherDto>(model); var result = await service.CreateAsync(role); if (result.IsSuccess) { string message = ($"Student Created - {result.Entity.Id}"); returnMessage = new HttpResponseMessage(HttpStatusCode.Created); returnMessage.RequestMessage = new HttpRequestMessage(HttpMethod.Post, message); } else { returnMessage = new HttpResponseMessage(HttpStatusCode.ExpectationFailed); returnMessage.RequestMessage = new HttpRequestMessage(HttpMethod.Post, result.GetErrorString()); } return(returnMessage); }