public async Task <IActionResult> Store([FromForm] OrderCustomerStoreViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } if (!HttpContext.Session.TryGetValue("@order-number", out var value)) { return(RedirectToAction("Index", "Product")); } var orderNumber = new Guid(value); var result = await _orderService.AddCustomer(orderNumber, viewModel); if (result.IsFailure) { TempData["Failure"] = "Não foi possível confirmar seus dados"; return(View(viewModel)); } return(RedirectToAction("Show", "OrderDetails")); }
public async Task <IActionResult> Store() { if (!HttpContext.Session.TryGetValue("@order-number", out var value)) { return(RedirectToAction("Index", "Product")); } var orderNumber = new Guid(value); var result = await _orderService.FindByNumber(orderNumber); if (result.IsFailure) { TempData["Failure"] = "Não foi possível carregar seus dados"; return(View()); } var order = result.Value; var viewModel = new OrderCustomerStoreViewModel { Name = order.CustomerName, Email = order.CustomerEmail, Phone = order.CustomerPhone }; return(View(viewModel)); }
public ActionResult Store([FromRoute] Guid number, [FromBody] OrderCustomerStoreViewModel viewModel) { var maybeOrder = _orderRepository.FindByNumber(number); if (!maybeOrder.HasValue) { return(NotFound()); } var customer = _mapper.Map <Customer>(viewModel); maybeOrder.Value.Customer = customer; _uow.Commit(); return(NoContent()); }
public async Task <Result> AddCustomer(Guid orderNumber, OrderCustomerStoreViewModel customer) { try { var client = _clientFactory.CreateClient("Api"); var json = JsonConvert.SerializeObject(customer); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"Order/{orderNumber}/Customer", content); response.EnsureSuccessStatusCode(); return(Result.Ok()); } catch (HttpRequestException ex) { _logger.LogError(ex, string.Empty); return(Result.Fail(ex.Message)); } }