Exemple #1
0
        public async Task <IActionResult> PutProductCategory([FromRoute] Guid id, [FromBody] ProductCategory productCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productCategory.ProductCategoryId)
            {
                return(BadRequest());
            }

            _context.Entry(productCategory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("ProductId,Name,CreatedDate,ModifiedDate,Quantity,Available,Price,Image,MeasuringUnitId")] Product product)
        {
            if (ModelState.IsValid)
            {
                product.ProductId = Guid.NewGuid();
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MeasuringUnitId"] = new SelectList(_context.MeasuringUnit, "MeasuringUnitId", "Name", product.MeasuringUnitId);
            return(View(product));
        }
        public async Task <IActionResult> PutReviewContent([FromRoute] Guid id, [FromBody] ReviewContent reviewContent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != reviewContent.ReviewContentId)
            {
                return(BadRequest());
            }

            _context.Entry(reviewContent).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReviewContentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("MeasuringUnitId,Name,Unit,Description")] MeasuringUnit measuringUnit)
        {
            measuringUnit.CreatedBy    = User.Identity.Name;
            measuringUnit.ModifiedBy   = User.Identity.Name;
            measuringUnit.CreatedDate  = DateTime.Today;
            measuringUnit.ModifiedDate = DateTime.Today;

            if (ModelState.IsValid)
            {
                measuringUnit.MeasuringUnitId = Guid.NewGuid();
                _context.Add(measuringUnit);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(measuringUnit));
        }
Exemple #5
0
        public async Task <IActionResult> Create([Bind("CategoryId,Name,Description")] Category category)
        {
            category.CreatedDate  = DateTime.Today;
            category.ModifiedDate = DateTime.Today;
            category.CreatedBy    = User.Identity.Name;
            category.ModifiedBy   = User.Identity.Name;

            if (ModelState.IsValid)
            {
                category.CategoryId = Guid.NewGuid();
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> CreateOrder(User user)
        {
            try
            {
                Order order = new Order();
                order.UserId       = user.UserId;
                order.DateCreate   = DateTime.Now;
                order.DateDelivery = DateTime.Now.AddDays(7);
                order.IsDelivery   = false;
                _context.Order.Add(order);
                await _context.SaveChangesAsync();



                if (HttpContext.Session.GetObject <List <Cart> >("cartShop") != null)
                {
                    carts = HttpContext.Session.GetObject <List <Cart> >("cartShop");


                    foreach (var item in carts)
                    {
                        OrderDetails orderDetails = new OrderDetails();
                        orderDetails.OrderId      = order.OrderId;
                        orderDetails.ProductId    = item.Product.ProductId;
                        orderDetails.Quantity     = item.Quantity;
                        orderDetails.PriceForItem = item.Product.Price;

                        _context.OrderDetail.Add(orderDetails);
                        await _context.SaveChangesAsync();
                    }

                    return(RedirectToAction("OrderDetails", "CheckOut", new { id = order.OrderId }));
                }
            }
            catch (Exception ex)
            {
                TempData["Message"] = "Error" + ex.Message;
                return(View("CreateUser", user));
            }



            TempData["Message"] = "Your cart is not find!";
            return(RedirectToAction("Index", "Cart"));
        }
Exemple #7
0
        public async Task <IActionResult> Create([Bind("ProductCategoryId,ProductId,CategoryId")] ProductCategory productCategory)
        {
            productCategory.CreatedBy    = User.Identity.Name;
            productCategory.ModifiedBy   = User.Identity.Name;
            productCategory.ModifiedDate = DateTime.Today;
            productCategory.CreatedDate  = DateTime.Today;

            if (ModelState.IsValid)
            {
                productCategory.ProductCategoryId = Guid.NewGuid();
                _context.Add(productCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "Name", productCategory.CategoryId);
            ViewData["ProductId"]  = new SelectList(_context.Product, "ProductId", "Name", productCategory.ProductId);
            return(View(productCategory));
        }
Exemple #8
0
        public async Task <IActionResult> Create(Guid id, [Bind("ProductId,Name,CreatedDate,ModifiedDate,Quantity,Available,Price,Image,Description,MeasuringUnitId")]  Product product)
        {
            if (Request.Form.Files["Image"] != null)
            {
                IFormFile    file    = Request.Form.Files["Image"];
                var          stream  = file.OpenReadStream();
                BinaryReader br      = new BinaryReader(stream);
                byte[]       imgdata = br.ReadBytes((int)stream.Length);
                product.Image = imgdata;
            }



            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MeasuringUnitId"] = new SelectList(_context.MeasuringUnit, "MeasuringUnitId", "Unit", product.MeasuringUnitId);
            return(View(product));
        }
Exemple #9
0
        public async Task <IActionResult> AddToCart(Guid id, int q)
        {
            if (id == null)
            {
                return(NotFound());
            }
            else if (q == 0)
            {
                TempData["Message"] = "Quantity products is 0, Please insert quantity products into your cart";
                return(Json(Url.Action("Details", "WebShop", new { id = id.ToString() })));
            }


            Cart  cart = null;
            Int32?numberElementInCart = 0;

            try
            {
                Product product = await _context.Product.FirstOrDefaultAsync(x => x.ProductId == id);

                if (HttpContext.Session.GetInt32("count") != null)
                {
                    numberElementInCart = HttpContext.Session.GetInt32("count");
                }


                if (product != null)
                {
                    if (product.Quantity > 0 && product.Available)
                    {
                        //nova kartica
                        if (HttpContext.Session.GetObject <List <Cart> >("cartShop") != null)
                        {
                            carts = HttpContext.Session.GetObject <List <Cart> >("cartShop");

                            if (carts.Where(x => x.Product.ProductId == product.ProductId).Any())
                            {
                                cart = carts.Where(x => x.Product.ProductId == product.ProductId).FirstOrDefault();
                                carts.Remove(cart);
                                cart.Quantity    = cart.Quantity + q;
                                product.Quantity = product.Quantity - q;
                                carts.Add(cart);
                            }
                            else
                            {
                                cart                = new Cart();
                                cart.Product        = product;
                                cart.Quantity       = cart.Quantity + q;
                                product.Quantity    = product.Quantity - q;
                                numberElementInCart = numberElementInCart + 1;
                                carts.Add(cart);
                            }
                        }
                        else
                        {
                            cart                = new Cart();
                            cart.Product        = product;
                            cart.Quantity       = cart.Quantity + q;
                            product.Quantity    = product.Quantity - q;
                            numberElementInCart = numberElementInCart + 1;
                            carts.Add(cart);
                        }


                        if (product.Quantity <= 0)
                        {
                            product.Available = false;
                        }
                        _context.Entry(product).State = EntityState.Modified;
                        await _context.SaveChangesAsync();

                        TempData["Message"] = "Product " + product.Name + " add to cart!";
                    }
                    else
                    {
                        TempData["Message"] = "Product " + product.Name + " not available!";
                        return(Json(Url.Action("Index", "WebShop")));
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                TempData["Message"] = ex.Message;
            }

            //vračam košaricu u session
            HttpContext.Session.SetInt32("count", numberElementInCart.Value);
            //nova kartica
            HttpContext.Session.SetObject("cartShop", carts);
            return(Json(Url.Action("Index", "WebShop")));
        }