public async Task <ActionResult> ModifyAccountDetails(ModifyAccountDetailsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = UserManager.FindById(User.Identity.GetUserId());
                if (user == null)
                {
                    return(View("Error"));
                }

                user.Name                         = model.Name;
                user.PhoneNumber                  = model.PrimaryPhoneNumber;
                user.SecondaryPhoneNumber         = model.SecondaryPhoneNumber;
                user.PreferredCommunicationMethod = model.PreferredCommunicationMethod;
                user.DefaultAddress               = model.DefaultAddress;

                var result = await UserManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    AuditUser.LogAudit(2, "", user.Id);

                    TempData["message"] = string.Format
                                              ("Your account details have been updated.");

                    return(RedirectToAction("Index"));
                }
            }

            return(View(model));
        }
        public ActionResult ViewProductModal(int id, int supplierNumber, int quantity)
        {
            string       userId = User.Identity.GetUserId();
            ShoppingCart cart   = GetCartFromSession(userId);

            if (User.Identity.Name != null)
            {
                if (User.Identity.Name == ConfigurationManager.AppSettings["developerIdentity"])
                {
                }
                else
                {
                    AuditUser.LogAudit(32, "Hit", userId);
                }
            }
            else
            {
                AuditUser.LogAudit(32, "Hit");
            }

            ViewProductViewModel model = new ViewProductViewModel(id, supplierNumber, quantity, cart.Order.OrderNumber);

            if (model == null)
            {
                return(RedirectToAction("Departments", "Product"));
            }

            return(PartialView("_ViewProductModal", model));
        }
Beispiel #3
0
        public async Task <ActionResult> ConfirmEmail(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(View("Error"));
            }

            var result = await UserManager.ConfirmEmailAsync(userId, code);

            if (result.Succeeded)
            {
                var user = UserManager.FindById(userId);
                if (!string.IsNullOrWhiteSpace(user.UnConfirmedEmail))
                {
                    user.Email            = user.UnConfirmedEmail;
                    user.UserName         = user.UnConfirmedEmail;
                    user.UnConfirmedEmail = "";

                    UserManager.Update(user);
                }

                AuditUser.LogAudit(3, "", user.Id);
            }

            return(View(result.Succeeded ? "ConfirmEmail" : "Error"));
        }
        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 CancelOrder()
        {
            string       userId = User.Identity.GetUserId();
            ShoppingCart cart   = GetCartFromSession(userId);

            cart.CancelOrder(userId);
            AuditUser.LogAudit(29, string.Format("Order Number: {0}", cart.Order.OrderNumber), User.Identity.GetUserId());

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #6
0
        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 LockOrder(ConfirmOrderViewModel confirmModel)
        {
            string       userId      = User.Identity.GetUserId();
            ShoppingCart sessionCart = GetCartFromSession(userId);

            if (ModelState.IsValid)
            {
                sessionCart.Order.OrderStatus = "Locked";
                sessionCart.Save();
                AuditUser.LogAudit(28, string.Format("Order Number: {0}", sessionCart.Order.OrderNumber), User.Identity.GetUserId());

                string          reference = sessionCart.Order.OrderNumber.ToString();
                decimal         amount    = sessionCart.Order.TotalOrderValue * 100;
                ApplicationUser user      = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

                PaymentGatewayIntegration payObject = new PaymentGatewayIntegration(reference, amount, user.Email);

                payObject.Execute();

                if (!string.IsNullOrEmpty(payObject.Pay_Request_Id) && !string.IsNullOrEmpty(payObject.Checksum))
                {
                    ConfirmOrderViewModel model = new ConfirmOrderViewModel(sessionCart, payObject.Pay_Request_Id, payObject.Checksum);
                    model.TermsAndConditions = confirmModel.TermsAndConditions;

                    return(View("PayShoppingCart", model));
                }
                else
                {
                    ConfirmOrderViewModel model = new ConfirmOrderViewModel(sessionCart);

                    return(View("ConfirmShoppingCart", model));
                }
            }
            else
            {
                ConfirmOrderViewModel model = new ConfirmOrderViewModel(sessionCart);
                model.TermsAndConditions = confirmModel.TermsAndConditions;

                return(View("ConfirmShoppingCart", model));
            }
        }
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }

                AuditUser.LogAudit(4, "", user.Id);

                return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(result);
            return(View(model));
        }
Beispiel #9
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl, string loginProvider)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }

                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);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    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);

                        AuditUser.LogAudit(1, "", user.Id);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl     = returnUrl;
            ViewBag.LoginProvider = loginProvider;

            return(View(model));
        }
        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));
            }
        }
        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 ActionResult UpdateDeliveryDetails(SaveCartViewModel model)
        {
            string           userId      = User.Identity.GetUserId();
            ShoppingCart     sessionCart = GetCartFromSession(userId);
            FreeMarketObject result;

            TimeSpan startTime = new TimeSpan(8, 0, 0);
            TimeSpan endTime   = new TimeSpan(17, 0, 0);

            if (model.DeliveryOptions == null || model.DeliveryOptions.SelectedDeliveryType == null)
            {
                ModelState.AddModelError("", "Please select a delivery option");
            }

            if (ModelState.IsValid)
            {
                if (!(model.prefDeliveryDateTime.Value.TimeOfDay > startTime &&
                      model.prefDeliveryDateTime.Value.TimeOfDay < endTime &&
                      model.prefDeliveryDateTime.Value > DateTime.Today &&
                      (model.prefDeliveryDateTime.Value.DayOfWeek == DayOfWeek.Monday ||
                       model.prefDeliveryDateTime.Value.DayOfWeek == DayOfWeek.Tuesday ||
                       model.prefDeliveryDateTime.Value.DayOfWeek == DayOfWeek.Wednesday ||
                       model.prefDeliveryDateTime.Value.DayOfWeek == DayOfWeek.Thursday ||
                       model.prefDeliveryDateTime.Value.DayOfWeek == DayOfWeek.Friday)))
                {
                    model.SetAddressNameOptions(userId, model.SelectedAddress);

                    return(View("CheckoutDeliveryDetails", model));
                }

                sessionCart.UpdateDeliveryDetails(model);
                result = new FreeMarketObject {
                    Result = FreeMarketResult.NoResult
                };
                if (model.AddressName != "Current")
                {
                    result = CustomerAddress.AddOrUpdateAddress(model, userId);
                }

                AuditUser.LogAudit(27, string.Format("Order Number: {0}", sessionCart.Order.OrderNumber), User.Identity.GetUserId());

                if (result.Result == FreeMarketResult.Success)
                {
                    TempData["message"] = result.Message;
                }
                else
                {
                    TempData["errorMessage"] = result.Message;
                }

                if (Request.IsAjaxRequest())
                {
                    return(JavaScript("window.location.reload();"));
                }
                else
                {
                    return(RedirectToAction("ChoosePaymentOption", "ShoppingCart"));
                }
            }

            model.SetAddressNameOptions(userId, model.SelectedAddress);

            decimal localCourierCost = sessionCart.CalculateLocalCourierFeeAdhoc(int.Parse(model.Address.AddressPostalCode));
            decimal courierCost      = sessionCart.CalculateCourierFeeAdhoc(int.Parse(model.Address.AddressPostalCode));
            decimal postOfficeCost   = sessionCart.CalculatePostalFee();

            model.SetDeliveryOptions(sessionCart.Order, /*localCourierCost,*/ courierCost, postOfficeCost);
            model.SetTextBlocks();

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_SaveCartModal", model));
            }
            else
            {
                return(View("CheckoutDeliveryDetails", model));
            }
        }