public virtual ActionResult Confirm(OrderConfirmViewModel model) { var orderUtils = new OrderUtils(_context, CurrentUserId); if (!model.OrderConfirmed) { // Regenerate the model model = orderUtils.GetConfirmModel(model.ProductId); ModelState.AddModelError("OrderConfirmed", "You must check the confirmation box to activate this license"); return View(model); } var createdOrder = orderUtils.CreateOrder(model.ProductId); if (createdOrder.OrderStatus == OrderStatus.AwaitingPayment) return RedirectToAction(MVC.Products.Pay.Index(createdOrder.Id)); else if (createdOrder.OrderStatus != OrderStatus.Completed) throw new InvalidOperationException( string.Format("Order status of {0} is not supported", createdOrder.OrderStatus.ToString())); // Order was completed as it was free orderUtils.ActivateOrderedLicenses(createdOrder); string LicenseType = orderUtils.GetLicenseDescription(createdOrder.FillPerfectLicenses.First().LicenseType); return RedirectToAction( MVC.Products.FillPerfect.LicenseActivated( (Guid)_context.Users.Find(createdOrder.OrderedForId).FillPerfectKey, createdOrder.FillPerfectLicenses.First().EffectiveDate, createdOrder.FillPerfectLicenses.First().ExpirationDate, LicenseType)); }
public virtual ActionResult ConfirmFillPerfectOrgOrder(FillPerfectOrgLicenseConfirmViewModel model) { var orderUtils = new OrderUtils(_context, CurrentUserId); if (!model.OrderConfirmed) { // Regenerate the model model = orderUtils.GetFpOrgConfirmModel(); ModelState.AddModelError("OrderConfirmed", "You must check the confirmation box to activate this license"); return(View(model)); } // Regenerate the model for license details model = orderUtils.GetFpOrgConfirmModel(); // Create the order and automatically activate the license var order = orderUtils.CreateOrder(); order.FillPerfectLicenses.Add(new FpUserLicense { LicenseType = FillPerfectLicenseType.OrganizationGranted, EffectiveDate = model.ActivatedLicenseExpiratioDate >= model.EffectiveLicenseDate ? model.ActivatedLicenseExpiratioDate : model.EffectiveLicenseDate, ExpirationDate = model.ExpirationDate }); // Make sure the user has a FP key var user = _context.Users.Find(order.OrderedForId); if (user.FillPerfectKey == null) { user.FillPerfectKey = Guid.NewGuid(); } _context.SaveChanges(); // Show the user confirmation string orgName = _context.Users.Where(x => x.Id == CurrentUserId).Select(x => x.Organization.Name).FirstOrDefault(); return(RedirectToAction( MVC.Products.FillPerfect.LicenseActivated( (Guid)user.FillPerfectKey, order.FillPerfectLicenses.First().EffectiveDate, order.FillPerfectLicenses.First().ExpirationDate, "License granted by " + orgName))); }
public virtual ActionResult Confirm(OrderConfirmViewModel model) { var orderUtils = new OrderUtils(_context, CurrentUserId); if (!model.OrderConfirmed) { // Regenerate the model model = orderUtils.GetConfirmModel(model.ProductId); ModelState.AddModelError("OrderConfirmed", "You must check the confirmation box to activate this license"); return(View(model)); } var createdOrder = orderUtils.CreateOrder(model.ProductId); if (createdOrder.OrderStatus == OrderStatus.AwaitingPayment) { return(RedirectToAction(MVC.Products.Pay.Index(createdOrder.Id))); } else if (createdOrder.OrderStatus != OrderStatus.Completed) { throw new InvalidOperationException( string.Format("Order status of {0} is not supported", createdOrder.OrderStatus.ToString())); } // Order was completed as it was free orderUtils.ActivateOrderedLicenses(createdOrder); string LicenseType = orderUtils.GetLicenseDescription(createdOrder.FillPerfectLicenses.First().LicenseType); return(RedirectToAction( MVC.Products.FillPerfect.LicenseActivated( (Guid)_context.Users.Find(createdOrder.OrderedForId).FillPerfectKey, createdOrder.FillPerfectLicenses.First().EffectiveDate, createdOrder.FillPerfectLicenses.First().ExpirationDate, LicenseType))); }
public virtual ActionResult ConfirmFillPerfectOrgOrder(FillPerfectOrgLicenseConfirmViewModel model) { var orderUtils = new OrderUtils(_context, CurrentUserId); if (!model.OrderConfirmed) { // Regenerate the model model = orderUtils.GetFpOrgConfirmModel(); ModelState.AddModelError("OrderConfirmed", "You must check the confirmation box to activate this license"); return View(model); } // Regenerate the model for license details model = orderUtils.GetFpOrgConfirmModel(); // Create the order and automatically activate the license var order = orderUtils.CreateOrder(); order.FillPerfectLicenses.Add(new FpUserLicense { LicenseType = FillPerfectLicenseType.OrganizationGranted, EffectiveDate = model.ActivatedLicenseExpiratioDate >= model.EffectiveLicenseDate ? model.ActivatedLicenseExpiratioDate : model.EffectiveLicenseDate, ExpirationDate = model.ExpirationDate }); // Make sure the user has a FP key var user = _context.Users.Find(order.OrderedForId); if (user.FillPerfectKey == null) user.FillPerfectKey = Guid.NewGuid(); _context.SaveChanges(); // Show the user confirmation string orgName = _context.Users.Where(x => x.Id == CurrentUserId).Select(x => x.Organization.Name).FirstOrDefault(); return RedirectToAction( MVC.Products.FillPerfect.LicenseActivated( (Guid)user.FillPerfectKey, order.FillPerfectLicenses.First().EffectiveDate, order.FillPerfectLicenses.First().ExpirationDate, "License granted by " + orgName)); }