示例#1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var customer = new Customer
                    {
                        Firstname = model.Firstname,
                        Lastname  = model.Lastname,

                        BillingAdress = model.BillingAdress,
                        BillingCity   = model.BillingCity,
                        BillingZip    = model.BillingZip,

                        DeliveryAdress = model.DeliveryAdress,
                        DeliveryCity   = model.DeliveryCity,
                        DeliveryZip    = model.DeliveryZip,

                        EmailAdress = model.Email,
                        PhoneNumber = model.PhoneNumber
                    };

                    WebShopMobileDb Db = new WebShopMobileDb();

                    Db.Customers.Add(customer);
                    Db.SaveChanges();

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);


                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#2
0
        // GET: Pdf
        public ActionResult Receipt(int orderId, string payment, float total)
        {
            WebShopMobileDb Db   = new WebShopMobileDb();
            var             user = User.Identity.Name;

            var model    = Methods.FindCartOrder(user);
            var customer = Db.Customers.FirstOrDefault(x => x.EmailAdress == user);

            var model2 = Db.Orders.FirstOrDefault(x => x.Id == model.Id);

            model2.Processed = true;
            Db.SaveChanges();

            model.OrderDate = DateTime.Now.ToShortDateString();
            var reciept = new RecieptViewModel(model, customer, payment, total);

            return(Pdf(reciept));
        }
示例#3
0
        public ActionResult EditUser(UserViewModel userView)
        {
            var user     = AppDb.Users.FirstOrDefault(x => x.Email == userView.Email);
            var customer = Db.Customers.FirstOrDefault(x => x.EmailAdress == userView.Email);

            user.Email           = userView.Email;
            customer.EmailAdress = userView.Email;

            user.EmailConfirmed = userView.EmailConfirmed;

            user.PhoneNumber     = userView.PhoneNumber;
            customer.PhoneNumber = userView.PhoneNumber;

            user.PhoneNumberConfirmed = userView.PhoneNumberConfirmed;

            customer.Firstname = userView.Firstname;
            customer.Lastname  = userView.Lastname;

            customer.BillingAdress = userView.BillingAdress;
            customer.BillingCity   = userView.BillingCity;
            customer.BillingZip    = userView.BillingZip;

            customer.DeliveryAdress = userView.DeliveryAdress;
            customer.DeliveryCity   = userView.DeliveryCity;
            customer.DeliveryZip    = userView.DeliveryZip;

            user.LockoutEnabled = userView.LockoutEnabled;

            if (userView.UserRoles != null)
            {
                foreach (var item in userView.UserRoles)
                {
                    var roleId = AppDb.Roles.FirstOrDefault(x => x.Name == item).Id;
                    var role   = user.Roles.FirstOrDefault(x => x.RoleId == roleId);
                    user.Roles.Remove(role);
                }
            }

            AppDb.SaveChanges();
            Db.SaveChanges();

            return(RedirectToAction("AllUsers"));
        }
示例#4
0
        public ActionResult RemoveFromCart(int cellId, int orderId)
        {
            var model = Db.Orders.Include("OrderRows").FirstOrDefault(x => x.Id == orderId);

            var cell = model.OrderRows.FirstOrDefault(x => x.Id == cellId);

            model.OrderRows.Remove(cell);
            Db.OrderRows.Remove(cell);

            if (model.OrderRows.Count == 0)
            {
                Db.Orders.Remove(model);
            }

            Db.SaveChanges();

            if (Request.IsAjaxRequest())
            {
                return(RedirectToAction("Cart", new { remove = true }));
            }

            return(RedirectToAction("Cart"));
        }