public async Task <IActionResult> Profile()
        {
            string UserName = db.GetUserName(HttpContext);
            User   user     = await db.User.Include(p => p.Profile).ThenInclude(a => a.Address).FirstOrDefaultAsync(x => x.Login == UserName);

            if (user.Profile == null)
            {
                user.Profile = new UserProfile
                {
                    Address = new Address()
                };
                db.User.Update(user);
                await db.SaveChangesAsync();
            }
            UserProfile          profile = user.Profile;
            UserProfileViewModel model   = new UserProfileViewModel
            {
                Login      = user.Login,
                Email      = user.Email,
                FirstName  = profile.FirstName,
                SecondName = profile.SecondName,
                City       = profile.Address.City,
                Street     = profile.Address.Street,
                Building   = profile.Address.Building,
                Flat       = profile.Address.Flat,
                PostalCode = profile.Address.PostalCode
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task MigrateCart(string userName)
        {
            string ShoppingCartId = db.GetUserName(HttpContext);
            var    shoppingCart   = db.Cart.Where(c => c.CartId == ShoppingCartId);

            foreach (Cart item in shoppingCart)
            {
                item.CartId = userName;
            }
            HttpContext.Session.SetString("CartId", userName);
            await db.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Editor(int?templateId)
        {
            Template template = await db.Template.Include(p => p.Product).Include(u => u.User).FirstOrDefaultAsync(x => x.Id == templateId);

            if (template != null)
            {
                string UserName = db.GetUserName(HttpContext);
                if ((template.User != null && template.User.Login == UserName) || template.Name == UserName)
                {
                    var viewModel = new EditorViewModel
                    {
                        CategoryId = template.Product.CategoryId,
                        templateId = template.Id,
                        Template   = JsonSerializer.Deserialize <TemplateSerializer>(template.JsonTemplate)
                    };
                    return(View(viewModel));
                }
                return(StatusCode(StatusCodes.Status403Forbidden));
            }
            return(StatusCode(StatusCodes.Status404NotFound));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OrderConfirm()
        {
            OrderConfirm model = new OrderConfirm();

            if (User.Identity.IsAuthenticated)
            {
                string UserName = db.GetUserName(HttpContext);
                User   user     = await db.User.Include(p => p.Profile).ThenInclude(a => a.Address).FirstOrDefaultAsync(x => x.Login == UserName);

                if (user.Profile == null)
                {
                    user.Profile = new UserProfile
                    {
                        Address = new Address()
                    };
                    db.User.Update(user);
                    await db.SaveChangesAsync();
                }
                else
                {
                    model = new OrderConfirm
                    {
                        Login      = user.Login,
                        Email      = user.Email,
                        FirstName  = user.Profile.FirstName,
                        SecondName = user.Profile.SecondName,
                        City       = user.Profile.Address.City,
                        Street     = user.Profile.Address.Street,
                        Building   = user.Profile.Address.Building,
                        Flat       = user.Profile.Address.Flat,
                        PostalCode = user.Profile.Address.PostalCode
                    };
                }
            }
            return(View(model));
        }
        public ActionResult CartView()
        {
            string ShoppingCartId = db.GetUserName(HttpContext);
            var    ShoppingCart   = db.Cart.Include(paper => paper.Paper).
                                    Include(t => t.Template).ThenInclude(p => p.Product).ThenInclude(c => c.Category).
                                    Where(c => c.CartId == ShoppingCartId).ToList();
            var viewModel = new ShoppingCartViewModel
            {
                CartItems  = ShoppingCart,
                TotalPrice = GetTotal()
            };

            return(View(viewModel));
        }