示例#1
0
        public async Task <IActionResult> Edit(Product product)
        {
            logger.LogInformation("Product edit");
            Product productItem = EshopDBContext.Products.Where(prodI => prodI.ID == product.ID).FirstOrDefault();

            if (productItem != null)
            {
                if (ModelState.IsValid)
                {
                    productItem.ImageAlt = product.ImageAlt;

                    FileUpload fup = new FileUpload(Env.WebRootPath, "Products", "image");
                    if (String.IsNullOrWhiteSpace(product.ImageSrc = await fup.FileUploadAsync(product.Image)) == false)
                    {
                        productItem.ImageSrc = product.ImageSrc;
                    }

                    await EshopDBContext.SaveChangesAsync();

                    return(RedirectToAction(nameof(SelectProducts)));
                }
                else
                {
                    return(View(product));
                }
            }
            else
            {
                return(NotFound());
            }
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("ID,OrderNumber")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Name,LastName,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("OrderNumber,TotalPrice,UserId,ID,DateTimeCreated")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", order.UserId);
            return(View(order));
        }
        public async Task <IActionResult> Create([Bind("OrderID,ProductID,Amount,Price,ID,DateTimeCreated")] OrderItem orderItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderID"]   = new SelectList(_context.Order, "ID", "OrderNumber", orderItem.OrderID);
            ViewData["ProductID"] = new SelectList(_context.Products, "ID", "DataTarget", orderItem.ProductID);
            return(View(orderItem));
        }
示例#6
0
        public async Task <IActionResult> ApproveMainComment(int id)
        {
            logger.LogInformation("MainComment approval");
            MainComment mainCommentItem = _context.MainComments.Where(mcI => mcI.ID == id).FirstOrDefault();

            if (mainCommentItem != null)
            {
                mainCommentItem.Approved = true;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(CommentsShow)));
            }
            else
            {
                return(NotFound());
            }
        }
示例#7
0
        public async Task <IActionResult> ApproveOrderInSession()
        {
            if (HttpContext.Session.IsAvailable)
            {
                double totalPrice = 0;

                double discountPrice = 0.9;      //10% sleva
                double neededSum     = 30000000; //30M


                List <OrderItems> orderItems = HttpContext.Session.GetObject <List <OrderItems> >(orderItemsString);
                if (orderItems != null)
                {
                    foreach (OrderItems orderItem in orderItems)
                    {
                        totalPrice       += orderItem.Product.Price * orderItem.Amount;
                        orderItem.Product = null; //zde musime nullovat referenci na produkt, jinak by doslo o pokus jej znovu vlozit do databaze
                    }

                    User currentUser = await iSecure.GetCurrentUser(User);

                    if (currentUser.IsStudent == true)
                    {
                        totalPrice *= currentUser.Sleva;
                    }
                    if (totalPrice >= neededSum)
                    {
                        totalPrice *= discountPrice;
                    }


                    Order order = new Order()
                    {
                        OrderNumber = Convert.ToBase64String(Guid.NewGuid().ToByteArray()),
                        TotalPrice  = totalPrice,
                        OrderItems  = orderItems,
                        UserId      = currentUser.Id,
                    };



                    //We can add just the order; order items will be added automatically.
                    await EshopDBContext.AddAsync(order);

                    await EshopDBContext.SaveChangesAsync();



                    HttpContext.Session.Remove(orderItemsString);
                    HttpContext.Session.Remove(totalPriceString);

                    return(RedirectToAction(nameof(CustomerOrdersController.Index), nameof(CustomerOrdersController).Replace("Controller", ""), new { Area = nameof(Customer) }));
                }
            }

            return(RedirectToAction(nameof(HomeController.Index), nameof(HomeController).Replace("Controller", ""), new { Area = "" }));
        }
示例#8
0
        public async Task <IActionResult> Create(Carousel carousel)
        {
            logger.LogInformation("Create carousel");
            if (ModelState.IsValid)
            {
                carousel.ImageSrc = String.Empty;

                FileUpload fup = new FileUpload(Env.WebRootPath, "Carousels", "image");
                carousel.ImageSrc = await fup.FileUploadAsync(carousel.Image);

                EshopDBContext.Carousels.Add(carousel);
                await EshopDBContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Carousel)));
            }
            else
            {
                return(View(carousel));
            }
        }
示例#9
0
        public async Task <IActionResult> Create(Product product)
        {
            if (ModelState.IsValid)
            {
                product.ImageSrc = String.Empty;

                FileUpload fup = new FileUpload(Env.WebRootPath, "image", "Products");
                product.ImageSrc = await fup.FileUploadAsync(product.Image);

                EshopDBContext.Products.Add(product);

                await EshopDBContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Select)));
            }
            else
            {
                return(View(product));
            }
        }
示例#10
0
        public async Task <IActionResult> Comment(CommentsViewModel cvm)
        {
            bool approve     = false;
            User currentUser = await iSecure.GetCurrentUser(User);

            if (User.IsInRole(nameof(Roles.Admin)) || User.IsInRole(nameof(Roles.Manager)))
            {
                approve = true;
            }
            if (cvm.MainCommentId == 0)
            {
                MainComment commentItem = new MainComment()
                {
                    CommentMessage = cvm.Message,
                    UserId         = currentUser.Id,
                    ProductId      = cvm.ProductId,
                    Approved       = approve
                };

                EshopDBContext.Add(commentItem);

                await EshopDBContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Detail), new { id = commentItem.ProductId }));
            }
            else
            {
                SubComment commentItem = new SubComment()
                {
                    MainCommentId  = cvm.MainCommentId,
                    CommentMessage = cvm.Message,
                    UserId         = currentUser.Id,
                    Approved       = approve
                };
                EshopDBContext.Add(commentItem);
                await EshopDBContext.SaveChangesAsync();

                commentItem.MainComment = EshopDBContext.MainComments.Where(c => c.ID == commentItem.MainCommentId).FirstOrDefault();
                return(RedirectToAction(nameof(Detail), new { id = commentItem.MainComment.ProductId }));
            }
        }
示例#11
0
        public async Task <IActionResult> Delete(int id)
        {
            _context.CartItems.Remove(_context.CartItems.ToArray()[id]);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#12
0
        public async Task <IActionResult> Create(Product product)
        {
            if (ModelState.IsValid)
            {
                product.ImageSrc = String.Empty;

                FileUpload fup = new FileUpload(Env.WebRootPath, "Products", "image");
                product.ImageSrc = await fup.FileUploadAsync(product.Image);

                //mozno nefunguje - v tom pripade nastavit az pri vytvarani objednavky

                EshopDBContext.Products.Add(product);

                await EshopDBContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(product));
            }
        }
示例#13
0
        public async Task <IActionResult> AddToCart(int id)
        {
            var cartItem = new CartItem
            {
                CartProduct = EshopDBContext.Products.Where(carI => carI.ID == id).FirstOrDefault()
            };

            await EshopDBContext.CartItems.AddAsync(cartItem);

            //EshopDBContext.Entry(cartItem).State = EntityState.Added;

            await EshopDBContext.SaveChangesAsync();

            return(Redirect("https://localhost:44381/Admin/Cart"));
            //return RedirectToAction(nameof(Detail));
        }