public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var customer = new PflCustomerModel() { FirstName = model.FirstName, LastName = model.LastName, Address1 = model.Address1, City = model.City, CompanyName = model.CompanyName, CountryCode = model.CountryCode, Phone = model.Phone, PostalCode = model.PostalCode, State = model.State, Email = model.Email }; // Persist as a Pfl Customer _pflCustomerDbContext.Customers.Add(customer); _pflCustomerDbContext.SaveChanges(); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> PlaceOrder([FromBody] List <PflOrderItemModel> items) { try { _logger.LogDebug("Attempting to place order"); if (items == null || items.Count == 0) { _logger.LogError("Placing an Order requires that there is at least one Item to be placed"); return(new BadRequestObjectResult("Missing list of order items")); } // Grab Customer Information from DB PflCustomerModel customer = GetCustomerFromIdentity(); if (customer == null) { _logger.LogError("Customer not defined. Order cannot be placed."); return(new BadRequestObjectResult("Customer cannot be found. Order will not be placed")); } PflShipmentModel shipment = new PflShipmentModel() { ShipmentSequenceNumber = 1, FirstName = customer.FirstName, LastName = customer.LastName, Address1 = customer.Address1, City = customer.City, CompanyName = customer.CompanyName, CountryCode = customer.CountryCode, Email = customer.Email, Phone = customer.Phone, PostalCode = customer.PostalCode, State = customer.State }; PflOrderModel order = new PflOrderModel() { Items = items, OrderCustomer = customer, Shipments = new List <PflShipmentModel>() { shipment } }; var orderNumber = await _pflApiSvc.PlaceOrderAsync(order); if (String.IsNullOrEmpty(orderNumber)) { string msg = "Order could not be placed successfully."; _logger.LogError(msg); return(new BadRequestObjectResult(msg)); } else { order.OrderNumber = orderNumber; } _logger.LogInformation("Successfully ordered {count} items. Order number is [{orderNumber}]", items.Count, orderNumber); return(new OkObjectResult(order)); } catch (Exception e) { _logger.LogError("Unable to process order due to exception. Message: {message}; StackTrace: {stacktrace}", e.Message, e.StackTrace); return(new BadRequestObjectResult("Unable to process order. " + e.Message)); } finally { _logger.LogDebug("Finished attempt to place order"); } }