public IActionResult Post([FromBody] Order order)
        {
            order.IsOrderCompleted = false;
            order.OrderPlaced      = DateTime.Now;
            _dbContext.Orders.Add(order);
            _dbContext.SaveChanges();

            var shoppingCartItems = _dbContext.ShoppingCartItems.Where(cart => cart.CustomerId == order.UserId);

            foreach (var item in shoppingCartItems)
            {
                var orderDetail = new OrderDetail()
                {
                    Price       = item.Price,
                    TotalAmount = item.TotalAmount,
                    Qty         = item.Qty,
                    ProductId   = item.ProductId,
                    OrderId     = order.Id,
                };
                _dbContext.OrderDetails.Add(orderDetail);
            }

            _dbContext.SaveChanges();
            _dbContext.ShoppingCartItems.RemoveRange(shoppingCartItems);
            _dbContext.SaveChanges();

            return(Ok(new { OrderId = order.Id }));
        }
示例#2
0
        public IActionResult Post([FromBody] ShoppingCartItem shoppingCartItem)
        {
            var shoppingCart = _dbContext.ShoppingCartItems.FirstOrDefault(s => s.ProductId == shoppingCartItem.ProductId && s.CustomerId == shoppingCartItem.CustomerId);

            if (shoppingCart != null)
            {
                shoppingCart.Qty        += shoppingCartItem.Qty;
                shoppingCart.TotalAmount = shoppingCart.Price * shoppingCart.Qty;
            }
            else
            {
                // Getting Product Price
                var productRecord = _dbContext.Products.Find(shoppingCartItem.ProductId);


                var sCart = new ShoppingCartItem()
                {
                    CustomerId  = shoppingCartItem.CustomerId,
                    ProductId   = shoppingCartItem.ProductId,
                    Price       = shoppingCartItem.Price,
                    Qty         = shoppingCartItem.Qty,
                    TotalAmount = (productRecord.Price) * (shoppingCartItem.Qty)
                };
                _dbContext.ShoppingCartItems.Add(sCart);
            }
            _dbContext.SaveChanges();
            return(StatusCode(StatusCodes.Status201Created));
        }
示例#3
0
        public ActionResult UserRegistration(Registers register, HttpPostedFileBase UserImage)
        {
            var list = new List <string>()
            {
                "Customer", "ShopOwner"
            };

            ViewBag.list = list;
            if (ModelState.IsValid)
            {
                string path = uploadImage(UserImage);
                if (path.Equals("-1"))
                {
                }
                else
                {
                    register.UserImage = path;
                    db.Registers.Add(register);
                    db.SaveChanges();
                    FlashMessage.Confirmation("Registration successfully");
                    return(RedirectToAction("UserRegistration"));
                }
            }
            return(View());
        }
 public IActionResult Post([FromBody] Complaint complaint)
 {
     complaint.Date = DateTime.Now;
     _dbContext.Complaints.Add(complaint);
     _dbContext.SaveChanges();
     return(Ok("Your Complaint has been registered"));
 }
        public IActionResult Post([FromBody] Product product)
        {
            var stream   = new MemoryStream(product.ImageArray);
            var guid     = Guid.NewGuid().ToString();
            var file     = $"{guid}.jpg";
            var folder   = "wwwroot";
            var response = FilesHelper.UploadImage(stream, folder, file);

            if (!response)
            {
                return(BadRequest());
            }
            else
            {
                product.ImageUrl = file;
                _dbContext.Products.Add(product);
                _dbContext.SaveChanges();
                return(StatusCode(StatusCodes.Status201Created));
            }
        }
示例#6
0
 public ActionResult DrawingOrder(DrawingOrders drawingorders, HttpPostedFileBase Image)
 {
     if (ModelState.IsValid)
     {
         string path = uploadImage(Image);
         if (path.Equals("-1"))
         {
         }
         else
         {
             drawingorders.Status = "Pending";
             drawingorders.Image  = path;
             db.DrawingOrders.Add(drawingorders);
             db.SaveChanges();
             FlashMessage.Confirmation("Order Information Submission Successfull!");
             return(RedirectToAction("DrawingOrder"));
         }
     }
     return(RedirectToAction("DrawingOrder"));
 }
        public ActionResult Create([Bind(Include = "ProductId,CompanyId,CategoryId,ProductName,Price,Quantity,ProductDetails,ProductImage")] Products products, HttpPostedFileBase ProductImage)
        {
            if (ModelState.IsValid)
            {
                string path = uploadImage(ProductImage);
                if (path.Equals("-1"))
                {
                }
                else
                {
                    products.ProductImage = path;
                    db.Products.Add(products);
                    db.SaveChanges();
                    FlashMessage.Confirmation("Product saved successfully");
                    return(RedirectToAction("Create"));
                }
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", products.CategoryId);
            ViewBag.CompanyId  = new SelectList(db.Companies, "CompanyId", "CompanyName", products.CompanyId);
            return(View(products));
        }
示例#8
0
 public ActionResult Edit([Bind(Include = "DrawingId,WoodId,StyleId,Height,Width,Quantity,Price,Details,Name,Image")] DrawingOrders orders)
 {
     if (ModelState.IsValid)
     {
         orders.Status          = "Confirmed";
         db.Entry(orders).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("TakeDrawingOrder"));
     }
     ViewBag.WoodId  = new SelectList(db.Woods, "WoodId", "WoodName", orders.WoodId);
     ViewBag.StyleId = new SelectList(db.FStyles, "StyleId", "StyleName", orders.StyleId);
     return(View(orders));
 }
 public ActionResult Create(Companies company)
 {
     if (ModelState.IsValid)
     {
         db.Companies.Add(company);
         db.SaveChanges();
         FlashMessage.Confirmation("Company saved successfully");
         return(RedirectToAction("Create"));
     }
     return(View());
 }