public ActionResult SecureDeliveryDetails() { string userId = User.Identity.GetUserId(); ShoppingCart sessionCart = GetCartFromSession(userId); sessionCart.Save(); if (sessionCart.IsAllVirtualOrder()) { using (FreeMarketEntities db = new FreeMarketEntities()) { OrderHeader order = db.OrderHeaders.Find(sessionCart.Order.OrderNumber); if (order != null) { sessionCart.Order.DeliveryType = "Virtual"; sessionCart.Save(); return(RedirectToAction("ConfirmInvoice", "ShoppingCart")); } } } //decimal localCourierCost = sessionCart.CalculateLocalCourierFee(); decimal courierCost = sessionCart.CalculateCourierFee(); decimal postOfficeCost = sessionCart.CalculatePostalFee(); SaveCartViewModel model = new SaveCartViewModel(userId, sessionCart.Order, courierCost, postOfficeCost); if (model == null) { return(RedirectToAction("Departments", "Product")); } return(View("CheckoutDeliveryDetails", model)); }
public ActionResult GetAddressPartial(int id) { string userId = User.Identity.GetUserId(); ShoppingCart sessionCart = GetCartFromSession(userId); CustomerAddress address = new CustomerAddress(); if (id == 0) { address = new CustomerAddress { AddressCity = sessionCart.Order.DeliveryAddressCity, AddressLine1 = sessionCart.Order.DeliveryAddressLine1, AddressLine2 = sessionCart.Order.DeliveryAddressLine2, AddressLine3 = sessionCart.Order.DeliveryAddressLine3, AddressLine4 = sessionCart.Order.DeliveryAddressLine3, AddressName = "Current", AddressNumber = 0, AddressPostalCode = sessionCart.Order.DeliveryAddressPostalCode, AddressSuburb = sessionCart.Order.DeliveryAddressSuburb, CustomerNumber = userId }; } using (FreeMarketEntities db = new FreeMarketEntities()) { address = db.CustomerAddresses .Where(c => c.CustomerNumber == userId && c.AddressNumber == id) .FirstOrDefault(); } SaveCartViewModel model = new SaveCartViewModel { Address = address, AddressName = address.AddressName }; return(PartialView("_CartModifyDeliveryDetails", model)); }
public ActionResult RateOrder(int orderNumber) { var user = UserManager.FindById(User.Identity.GetUserId()); if (user == null) { return(View("Error")); } OrderHeader order = new OrderHeader(); using (FreeMarketEntities db = new FreeMarketEntities()) { order = db.OrderHeaders.Find(orderNumber); if (order == null) { return(View("Error")); } } // Only allow the owner of the order to rate it. RateOrderViewModel model = new RateOrderViewModel(); if (user.Id == order.CustomerNumber) { model = new RateOrderViewModel(orderNumber); model.Unsubscribe = user.UnsubscribeFromRatings; return(View(model)); } else { return(RedirectToAction("Index", "Home")); } }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null /*|| !(await UserManager.IsEmailConfirmedAsync(user.Id))*/) { // Don't reveal that the user does not exist or is not confirmed return(View("ForgotPasswordConfirmation")); } // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); string html = ""; string message = ""; using (FreeMarketEntities db = new FreeMarketEntities()) { html = db.SiteConfigurations.First(c => c.Key == "Email: Reset Password")?.Value; message = html.Replace("{{0}}", callbackUrl); } await UserManager.SendEmailAsync(user.Id, "Reset Password", message); return(RedirectToAction("ForgotPasswordConfirmation", "Account")); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult GetDimensions(int productNumber) { string toReturn = ""; Product product; if (productNumber != 0) { using (FreeMarketEntities db = new FreeMarketEntities()) { product = db.Products .Where(c => c.ProductNumber == productNumber) .FirstOrDefault(); if (product != null) { if (product.Weight < 1) { toReturn = string.Format("{0} {1}", Math.Round(product.Weight.Value * 1000, 0), "Grams"); } else { toReturn = string.Format("{0} {1}", product.Weight, "KG"); } } } } return(Content(toReturn)); }
public JsonResult LoadMoreReviews(int productNumber, int supplierNumber, int size) { using (FreeMarketEntities db = new FreeMarketEntities()) { ProductReviewsCollection model = new ProductReviewsCollection(); model.ProductNumber = productNumber; model.SupplierNumber = supplierNumber; List <ProductReview> collection = db.ProductReviews .Where(c => c.ProductNumber == productNumber && c.SupplierNumber == supplierNumber && c.Approved == true) .OrderByDescending(p => p.ReviewId) .Skip(size) .Take(size) .ToList(); model.Reviews = collection; int modelCount = db.ProductReviews .Where(c => c.ProductNumber == productNumber && c.SupplierNumber == supplierNumber && c.Approved == true) .Count(); if (model.Reviews.Any()) { string modelString = RenderRazorViewToString("_RatingPartialLoadMore", model); return(Json(new { ModelString = modelString, ModelCount = modelCount })); } return(Json(model)); } }
public async Task <ActionResult> LockInvoice(ConfirmInvoiceViewModel confirmModel) { string userId = User.Identity.GetUserId(); ShoppingCart sessionCart = GetCartFromSession(userId); int orderNumber = sessionCart.Order.OrderNumber; if (ModelState.IsValid) { using (FreeMarketEntities db = new FreeMarketEntities()) { OrderHeader order = db.OrderHeaders.Find(orderNumber); if (order != null) { order.OrderStatus = "Invoiced"; db.Entry(order).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); OrderHeader.SendInvoice(userId, order.OrderNumber); AuditUser.LogAudit(28, string.Format("Order Number: {0}", order.OrderNumber), User.Identity.GetUserId()); sessionCart.Initialize(User.Identity.GetUserId()); } } return(RedirectToAction("PayInvoice", new { orderNumber = orderNumber })); } ConfirmInvoiceViewModel model = new ConfirmInvoiceViewModel(sessionCart); model.TermsAndConditions = confirmModel.TermsAndConditions; return(View("ConfirmInvoice", model)); }
public ActionResult GetPackageDetails(int id, int productNumber, int supplierNumber) { using (FreeMarketEntities db = new FreeMarketEntities()) { ProductSupplier product = db.ProductSuppliers.Find(productNumber, supplierNumber, id); return(PartialView("_CartViewProductModalPrice", product)); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Name = model.Name, PhoneNumber = model.PrimaryPhoneNumber, SecondaryPhoneNumber = model.SecondaryPhoneNumber, PreferredCommunicationMethod = model.PreferredCommunicationMethod, DefaultAddress = model.AddressName, UnsubscribeFromAllCorrespondence = false, UnsubscribeFromRatings = false, LastVisited = DateTime.Now }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { CustomerAddress.AddAddress(user.Id, model.AddressName, model.AddressLine1, model.AddressLine2 , model.AddressLine3, model.AddressLine4, model.AddressSuburb , model.AddressCity, model.AddressPostalCode); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); SetShoppingCartSession(user.Id); string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); string html = ""; string message = ""; using (FreeMarketEntities db = new FreeMarketEntities()) { html = db.SiteConfigurations.First(c => c.Key == "Email: Confirm Account")?.Value; message = html.Replace("{{0}}", user.Name).Replace("{{1}}", callbackUrl); } await UserManager.SendEmailAsync(user.Id, "Confirm your account", message); AuditUser.LogAudit(1, "", user.Id); return(RedirectToAction("Index", "Home")); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult GetAllowedSizes(int id) { using (FreeMarketEntities db = new FreeMarketEntities()) { ProductSize size = db.ProductSizes.Find(id); if (size == null) { return(Content("")); } return(Content(size.Description)); } }
public int PerformStockCheck(int id, int supplierNumber, int quantityRequested) { int currentStock = 0; using (FreeMarketEntities db = new FreeMarketEntities()) { currentStock = db.ProductCustodians .Where(c => c.ProductNumber == id && c.SupplierNumber == supplierNumber && c.QuantityOnHand >= quantityRequested) .Select(c => c.QuantityOnHand) .FirstOrDefault(); } return(currentStock); }
public ActionResult SendEmail(ContactUsViewModel model) { if (ModelState.IsValid) { EmailService service = new EmailService(); service.SendAsync(model.FromEmail, model.DestinationEmail, model.Message); return(View("ThankYouForYourEmail")); } using (FreeMarketEntities db = new FreeMarketEntities()) { model.SupportInfo = db.Supports.FirstOrDefault(); } return(View("Contact", model)); }
public ActionResult TermsAndConditionsModal() { string terms = ""; using (FreeMarketEntities db = new FreeMarketEntities()) { SiteConfiguration temp = db.SiteConfigurations .Where(c => c.Key == "TermsAndConditions") .FirstOrDefault(); if (temp != null) { terms = temp.Value; } } return(PartialView("_TermsAndConditionsModal", terms)); }
public ActionResult TermsAndConditions() { TermsAndConditionsViewModel model = new TermsAndConditionsViewModel(); using (FreeMarketEntities db = new FreeMarketEntities()) { SiteConfiguration temp = db.SiteConfigurations .Where(c => c.Key == "TermsAndConditions") .FirstOrDefault(); if (temp != null) { model.Content = temp.Value; } } return(View("TermsAndConditions", model)); }
public ActionResult PayInvoice(int orderNumber) { using (FreeMarketEntities db = new FreeMarketEntities()) { OrderHeader order = db.OrderHeaders.Find(orderNumber); if (order == null) { return(RedirectToAction("Cart")); } else { if (User.Identity.GetUserId() == order.CustomerNumber) { ShoppingCart cart = new ShoppingCart(orderNumber); PayInvoiceViewModel model = new PayInvoiceViewModel(cart); return(View("PayInvoice", model)); } } } return(RedirectToAction("Cart")); }
public ActionResult GetAddress(int AddressNumber) { string toReturn = ""; CustomerAddress address; if (AddressNumber != 0) { using (FreeMarketEntities db = new FreeMarketEntities()) { address = db.CustomerAddresses .Where(c => c.AddressNumber == AddressNumber) .FirstOrDefault(); if (address != null) { toReturn = address .ToString(); } } } return(Content(toReturn)); }
public async Task <ActionResult> Notify(int?PAYGATE_ID, string PAY_REQUEST_ID, string REFERENCE, int TRANSACTION_STATUS, int RESULT_CODE, string AUTH_CODE, string CURRENCY, int AMOUNT, string RESULT_DESC, int TRANSACTION_ID, string RISK_INDICATOR, string PAY_METHOD, string PAY_METHOD_DETAIL, string USER1, string USER2, string USER3, string VAULT_ID, string PAYVAULT_DATA_1, string PAYVAULT_DATA_2, string CHECKSUM) { bool checksumPassed = false; bool priceSameAsRequest = false; PaymentGatewayParameter param = PaymentGatewayIntegration.GetParameters(); string id = ""; if (PAYGATE_ID == null) { id = param.PaymentGatewayID.ToString(); } else { id = PAYGATE_ID.ToString(); } string check = id + PAY_REQUEST_ID + REFERENCE + TRANSACTION_STATUS.ToString() + RESULT_CODE.ToString() + AUTH_CODE + CURRENCY + AMOUNT + RESULT_DESC + TRANSACTION_ID + RISK_INDICATOR + PAY_METHOD + PAY_METHOD_DETAIL + USER1 + USER2 + USER3 + VAULT_ID + PAYVAULT_DATA_1 + PAYVAULT_DATA_2 + param.Key; string checksum = Extensions.CreateMD5(check); if (CHECKSUM == checksum) { checksumPassed = true; using (FreeMarketEntities db = new FreeMarketEntities()) { if (!string.IsNullOrEmpty(REFERENCE)) { ValidatePaymentAmount_Result request = db.ValidatePaymentAmount(REFERENCE).FirstOrDefault(); if (request != null) { string requestedAmount = request.Amount.ToString(); if (requestedAmount == AMOUNT.ToString()) { priceSameAsRequest = true; string orderNumberString = REFERENCE.ToString(); if (db.PaymentGatewayMessages .Where(c => c.Reference == orderNumberString && c.TransactionStatus == TRANSACTION_STATUS) .FirstOrDefault() == null) { PaymentGatewayMessage message = new PaymentGatewayMessage { PayGate_ID = decimal.Parse(id), Pay_Request_ID = PAY_REQUEST_ID, Reference = REFERENCE, TransactionStatus = TRANSACTION_STATUS, Transaction_Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Result_Code = RESULT_CODE, Auth_Code = AUTH_CODE, Currency = CURRENCY, Amount = AMOUNT, Result_Desc = RESULT_DESC, Transaction_ID = TRANSACTION_ID, Risk_Indicator = RISK_INDICATOR, Pay_Method = PAY_METHOD, Pay_Method_Detail = PAY_METHOD_DETAIL, User1 = USER1, User2 = USER2, User3 = USER3, Vault_ID = VAULT_ID, Pay_Vault_Data1 = PAYVAULT_DATA_1, Pay_Vault_Data2 = PAYVAULT_DATA_2, Checksum_Passed = checksumPassed, PriceSameAsRequest = priceSameAsRequest }; db.PaymentGatewayMessages.Add(message); db.SaveChanges(); } try { if (TRANSACTION_STATUS == 1) { int orderNumber = int.Parse(REFERENCE); OrderHeader order = db.OrderHeaders.Find(orderNumber); if (order == null) { } else { if (order.OrderStatus == "Locked") { ShoppingCart.SetOrderConfirmedFromNotify(orderNumber); OrderHeader.SendConfirmationMessages(order.CustomerNumber, orderNumber); } } } } catch (Exception e) { ExceptionLogging.LogException(e); } AuditUser.LogAudit(35, string.Format("Order Number: {0}", REFERENCE)); } else { priceSameAsRequest = false; string orderNumberString = REFERENCE.ToString(); if (db.PaymentGatewayMessages .Where(c => c.Reference == orderNumberString && c.TransactionStatus == TRANSACTION_STATUS) .FirstOrDefault() == null) { PaymentGatewayMessage message = new PaymentGatewayMessage { PayGate_ID = decimal.Parse(id), Pay_Request_ID = PAY_REQUEST_ID, Reference = REFERENCE, TransactionStatus = TRANSACTION_STATUS, Transaction_Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Result_Code = RESULT_CODE, Auth_Code = AUTH_CODE, Currency = CURRENCY, Amount = AMOUNT, Result_Desc = RESULT_DESC, Transaction_ID = TRANSACTION_ID, Risk_Indicator = RISK_INDICATOR, Pay_Method = PAY_METHOD, Pay_Method_Detail = PAY_METHOD_DETAIL, User1 = USER1, User2 = USER2, User3 = USER3, Vault_ID = VAULT_ID, Pay_Vault_Data1 = PAYVAULT_DATA_1, Pay_Vault_Data2 = PAYVAULT_DATA_2, Checksum_Passed = checksumPassed, PriceSameAsRequest = priceSameAsRequest }; db.PaymentGatewayMessages.Add(message); db.SaveChanges(); } AuditUser.LogAudit(34, string.Format("Order Number: {0}. Request Amount: {1}. Notification Amount: {2}", REFERENCE, requestedAmount, AMOUNT)); try { int orderNumber = int.Parse(REFERENCE); OrderHeader.SendWarningEmail(orderNumber); } catch (Exception e) { ExceptionLogging.LogException(e); } } } } } } else { checksumPassed = false; using (FreeMarketEntities db = new FreeMarketEntities()) { string orderNumberString = REFERENCE.ToString(); if (db.PaymentGatewayMessages .Where(c => c.Reference == orderNumberString && c.TransactionStatus == TRANSACTION_STATUS) .FirstOrDefault() == null) { PaymentGatewayMessage message = new PaymentGatewayMessage { PayGate_ID = PAYGATE_ID, Pay_Request_ID = PAY_REQUEST_ID, Reference = REFERENCE, TransactionStatus = TRANSACTION_STATUS, Result_Code = RESULT_CODE, Auth_Code = AUTH_CODE, Currency = CURRENCY, Amount = AMOUNT, Result_Desc = RESULT_DESC, Transaction_ID = TRANSACTION_ID, Risk_Indicator = RISK_INDICATOR, Pay_Method = PAY_METHOD, Pay_Method_Detail = PAY_METHOD_DETAIL, User1 = USER1, User2 = USER2, User3 = USER3, Vault_ID = VAULT_ID, Pay_Vault_Data1 = PAYVAULT_DATA_1, Pay_Vault_Data2 = PAYVAULT_DATA_2, Checksum_Passed = checksumPassed }; db.PaymentGatewayMessages.Add(message); db.SaveChanges(); } AuditUser.LogAudit(34, string.Format("Order Number: {0}. Checksum failed.", REFERENCE)); try { int orderNumber = int.Parse(REFERENCE); OrderHeader.SendWarningEmail(orderNumber); } catch (Exception e) { ExceptionLogging.LogException(e); } } } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public async Task <ActionResult> UpdateReviews(RateOrderViewModel model) { bool error = false; foreach (Product p in model.Products.Products) { if (p.ProductRating == 0) { ModelState.AddModelError("", string.Format("{0}'s product rating may not be empty.", p.Description)); error = true; } if (p.PriceRating == 0) { ModelState.AddModelError("", string.Format("{0}'s price rating may not be empty.", p.Description)); error = true; } } if (model.CourierRatings != null) { foreach (CourierReview c in model.CourierRatings) { if (c.StarRating == 0) { ModelState.AddModelError("", string.Format("{0}'s rating may not be empty.", c.CourierName)); error = true; } } } if (error) { return(View("RateOrder", model)); } var user = UserManager.FindById(User.Identity.GetUserId()); if (user == null) { return(View("Error")); } user.UnsubscribeFromRatings = model.Unsubscribe; await UserManager.UpdateAsync(user); using (FreeMarketEntities db = new FreeMarketEntities()) { foreach (Product p in model.Products.Products) { if (p.ReviewId == null) { ProductReview review = new ProductReview { Author = user.Name, Date = DateTime.Now, OrderNumber = model.Order.OrderNumber, PriceRating = p.PriceRating, ProductNumber = p.ProductNumber, ReviewContent = p.ProductReviewText, StarRating = (short)p.ProductRating, SupplierNumber = p.SupplierNumber, UserId = user.Id, Approved = null }; db.ProductReviews.Add(review); } else { ProductReview review = db.ProductReviews.Find(p.ReviewId); if (review != null) { if (review.PriceRating != p.PriceRating || review.ReviewContent != p.ProductReviewText || review.StarRating != (short)p.ProductRating) { review.Date = DateTime.Now; review.PriceRating = p.PriceRating; review.ReviewContent = p.ProductReviewText; review.StarRating = (short)p.ProductRating; review.Approved = null; } db.Entry(review).State = System.Data.Entity.EntityState.Modified; } } } if (model.CourierRatings != null) { foreach (CourierReview cReview in model.CourierRatings) { if (cReview.ReviewId == 0) { CourierReview review = new CourierReview { Author = user.Name, Date = DateTime.Now, OrderNumber = model.Order.OrderNumber, ReviewContent = cReview.ReviewContent, StarRating = (short)cReview.StarRating, CourierNumber = cReview.CourierNumber, UserId = user.Id }; db.CourierReviews.Add(review); } else { CourierReview review = db.CourierReviews.Find(cReview.ReviewId); if (review != null) { review.Date = DateTime.Now; review.ReviewContent = cReview.ReviewContent; review.StarRating = (short)cReview.StarRating; db.Entry(review).State = System.Data.Entity.EntityState.Modified; } } } } db.SaveChanges(); return(RedirectToAction("Index", "Manage")); } }
public async Task <ActionResult> TransactionComplete(string PAY_REQUEST_ID, int TRANSACTION_STATUS, string CHECKSUM) { using (FreeMarketEntities db = new FreeMarketEntities()) { ThankYouViewModel model; ShoppingCart cart = GetCartFromSession(User.Identity.GetUserId()); int orderNumber = cart.Order.OrderNumber; PaymentGatewayParameter parameters = PaymentGatewayIntegration.GetParameters(); string checkSource = string.Format("{0}{1}{2}{3}{4}", parameters.PaymentGatewayID, PAY_REQUEST_ID, TRANSACTION_STATUS, cart.Order.OrderNumber.ToString(), parameters.Key); string checkSum = Extensions.CreateMD5(checkSource); if (checkSum == CHECKSUM) { if (TRANSACTION_STATUS == 1) { // Get the order from the database, not the session. OrderHeader order = db.OrderHeaders.Find(orderNumber); if (order == null) { } else { // This will be executed if the notify url did not receive a response yet. if (order.OrderStatus == "Locked") { cart.SetOrderConfirmed(User.Identity.GetUserId()); OrderHeader.SendConfirmationMessages(User.Identity.GetUserId(), orderNumber); } else { cart.Initialize(User.Identity.GetUserId()); } } AuditUser.LogAudit(33, string.Format("Order Number: {0} | Transaction Status: {1} | Pay Request Id: {2}", orderNumber, TRANSACTION_STATUS, PAY_REQUEST_ID), User.Identity.GetUserId()); } else { AuditUser.LogAudit(39, string.Format("Order Number: {0} | Transaction Status: {1} | Pay Request Id: {2}", orderNumber, TRANSACTION_STATUS, PAY_REQUEST_ID), User.Identity.GetUserId()); } } else { OrderHeader.SendWarningEmail(orderNumber); AuditUser.LogAudit(34, string.Format("Order Number: {0}", orderNumber), User.Identity.GetUserId()); model = new ThankYouViewModel { TransactionStatus = 999 }; return(View("ThankYou", model)); } model = new ThankYouViewModel { TransactionStatus = TRANSACTION_STATUS }; return(View("ThankYou", model)); } }