Ejemplo n.º 1
0
        public IActionResult Edit(int?id)
        {
            var model = new MembershipsEditViewModel();

            if (id.HasValue)
            {
                model.Membership = membershipData.GetMembershipById(id.Value);
            }
            else
            {
                model.Membership = new Membership();
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var membership = membershipData.GetMembershipById(Customer.MembershipId);
                Customer.Membership = membership;

                if (Customer.Id == 0)
                {
                    Customer = customerData.Create(Customer);
                    TempData["TempMessage"] = "New customer is created!";
                }
                else
                {
                    Customer = customerData.Update(Customer);
                    TempData["TempMessage"] = "Data for customer is updated!";
                }

                customerData.Commit();
                return(RedirectToPage("./List"));
            }

            var memberships = membershipData.GetMemberships().ToList().Select(p => new { Id = p.Id, Display = p.MembershipType });

            Memberships = new SelectList(memberships, "Id", "Display");
            Gender      = htmlHelper.GetEnumSelectList <Gender>();
            City        = htmlHelper.GetEnumSelectList <City>();
            return(Page());
        }
Ejemplo n.º 3
0
        public IActionResult Edit(CustomersEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var membership = membershipData.GetMembershipById(model.Customer.Id);
                model.Customer.Membership = membership;

                if (model.Customer.Id == 0)
                {
                    model.Customer          = customerData.Create(model.Customer);
                    TempData["TempMessage"] = "New customer is created!";
                }
                else
                {
                    model.Customer          = customerData.Update(model.Customer);
                    TempData["TempMessage"] = "Data for customer is updated!";
                }

                customerData.Commit();
                return(RedirectToAction("List"));
            }
            var memberships = membershipData.GetMemberships().ToList().Select(p => new { Id = p.Id, Display = p.MembershipType });

            model.Memberships = new SelectList(memberships, "Id", "Display");
            model.Gender      = htmlHelper.GetEnumSelectList <Gender>();
            model.City        = htmlHelper.GetEnumSelectList <City>();
            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                Memberships = membershipData.GetMemberships().Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.Type
                }).ToList();
                return(Page());
            }
            if (UserNew.MembershipId.HasValue)
            {
                var tempMembership = membershipData.GetMembershipById(UserNew.MembershipId.Value);
                UserNew.Membership = tempMembership;
            }
            IdentityResult result = await userManager.CreateAsync(UserNew, Password);

            if (result.Succeeded)
            {
                return(RedirectToPage("./ListUser"));
            }
            foreach (IdentityError error in result.Errors)
            {
                ModelState.AddModelError("", error.Description);
            }
            return(Page());
        }
Ejemplo n.º 5
0
 public IActionResult OnGet(int id)
 {
     Membership = membershipData.GetMembershipById(id);
     if (Membership == null)
     {
         return(RedirectToPage("./NotFound"));
     }
     return(Page());
 }
Ejemplo n.º 6
0
        public IActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(RedirectToPage("NotFound"));
            }

            Membership = membershipData.GetMembershipById(id.Value);

            if (Membership == null)
            {
                return(RedirectToPage("NotFound"));
            }

            return(Page());
        }
Ejemplo n.º 7
0
 public IActionResult OnGet(int?id)
 {
     if (id.HasValue)
     {
         Membership = membershipData.GetMembershipById(id.Value);
         if (Membership == null)
         {
             return(RedirectToPage("./NotFound"));
         }
     }
     else
     {
         Membership = new Core.Membership.Membership();
     }
     return(Page());
 }
Ejemplo n.º 8
0
        public async Task <IActionResult> OnPost()
        {
            Memberships     = membershipData.GetMemberships();
            ApplicationUser = await userManager.GetUserAsync(User);

            if (ModelState.IsValid)
            {
                foreach (var cartItem in HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList())
                {
                    OrderDetails.Add(new OrderDetail
                    {
                        Product  = productData.GetProductById(cartItem.Id),
                        Quantity = cartItem.Quantity
                    });

                    //
                    Product           = productData.GetProductById(cartItem.Id);
                    Product.Quantity -= cartItem.Quantity;
                    //
                }

                if (Selected != null)
                {
                    var membership = membershipData.GetMembershipById(Convert.ToInt32(Selected));
                    ApplicationUser.Membership = membership;
                    Order.OrderTotal           = cartBL.MemberOnCheckout(Convert.ToDouble(HttpContext.Session.GetString("TotalPrice")), ApplicationUser);
                }
                else
                {
                    Order.OrderTotal = Convert.ToDouble(HttpContext.Session.GetString("TotalPrice"));
                }
                Order.OrderDetails = OrderDetails;
                Order.UserId       = ApplicationUser.Id;
                //
                Order.DateOrdered = DateTime.Now;
                //
                orderData.CreateOrder(Order);
                orderData.Commit();
                HttpContext.Session.Remove("CartItems");
                return(RedirectToPage("/Order/CheckoutComplete"));
            }
            return(Page());
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> OnGet()
        {
            //ApplicationUser = await userManager.GetUserAsync(User);
            //if (ApplicationUser != null)
            //{
            //    if (ApplicationUser.IsMember)
            //    {
            //        var membership = membershipData.GetMembershipById(ApplicationUser.MembershipId.Value);
            //        ApplicationUser.Membership = membership;
            //    }


            //    if (HttpContext.Session.GetObjectFromJson<List<ShoppingCart>>("CartItems") != null)
            //    {
            //        CartItems = HttpContext.Session.GetObjectFromJson<List<ShoppingCart>>("CartItems").ToList();


            //        if (ApplicationUser.IsMember)
            //        {

            //            TotalPrice = cartBL.TotalPrice(CartItems, ApplicationUser.Membership.Discount);
            //        }
            //        else
            //        {
            //            TotalPrice = cartBL.TotalPrice(CartItems, 0);
            //        }
            //    }

            //    HttpContext.Session.SetString("TotalPrice", TotalPrice.ToString());
            //}
            //CartItems = HttpContext.Session.GetObjectFromJson<List<ShoppingCart>>("CartItems").ToList();

            //return Page();


            if (HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems") != null)
            {
                CartItems       = HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList();
                ApplicationUser = await userManager.GetUserAsync(User);

                if (ApplicationUser != null)
                {
                    if (ApplicationUser.IsMember)
                    {
                        var membership = membershipData.GetMembershipById(ApplicationUser.MembershipId.Value);
                        ApplicationUser.Membership = membership;
                        TotalPrice = cartBL.TotalPrice(CartItems, ApplicationUser.Membership.Discount);
                    }
                    else
                    {
                        TotalPrice = cartBL.TotalPrice(CartItems, 0);
                    }
                }
                else
                {
                    TotalPrice = cartBL.TotalPrice(CartItems, 0);
                }
                HttpContext.Session.SetString("TotalPrice", TotalPrice.ToString());
            }
            return(Page());
        }