public void Created(ItemCategoryDTO obj)
        {
            ItemCategory Create = new ItemCategory();

            Create.ItemCategoryName = obj.ItemCategoryName;
            Create.SignUpId         = obj.SignUpId;

            _db.Add(Create);
            _db.SaveChanges();
        }
Exemplo n.º 2
0
        public void AddGuestOrder(Guid guestOrderId)
        {
            var CheckIfGuestOrderExists = _context.Order.SingleOrDefault(x => x.Id == guestOrderId);

            if (CheckIfGuestOrderExists == null)
            {
                Order o = new Order();
                o.Id              = guestOrderId;
                o.DatePlaced      = DateTime.MinValue;
                o.Email           = null;
                o.OrderTotalPrice = 0;
                o.UserId          = Guid.Empty;
                o.OrderStatusId   = _context.OrderStatus.SingleOrDefault(x => x.Status == "Not_Checked_Out").Id;


                _context.Add(o);
                _context.SaveChanges();
            }
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Quantity,ProductId")] CartItem cartItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cartItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(Ok(cartItem));
        }
Exemplo n.º 4
0
        public Boolean AddOrderDetails(Guid orderId, Guid productId)
        {
            //Creating a new order detail
            OrderDetails o = new OrderDetails();

            o.OrderFk      = orderId;
            o.ProductFk    = productId;
            o.SellingPrice = _context.Products.SingleOrDefault(x => x.Id == productId).Price;

            var stockForProduct = _context.Products.SingleOrDefault(x => x.Id == productId).Stock;

            var orderDetail = _context.OrderDetails.FirstOrDefault(x => x.ProductFk == productId && x.OrderFk == orderId);

            //If there is this product already in the list and the user clicks on add to cart again -> increase the quantity.
            if (stockForProduct > 0)
            {
                if (orderDetail == null)
                {
                    o.Quantity = 1;
                    _context.Add(o);
                    _context.SaveChanges();
                }
                else
                {
                    orderDetail.Quantity++;
                    _context.Update(orderDetail);
                    _context.SaveChanges();
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
 public string FinishShoping(ShoppingCart shoppingCart)
 {
     shoppingCartDbContext.Add <ShoppingCart>(shoppingCart);
     try
     {
         shoppingCartDbContext.SaveChanges();
     }
     catch (DbUpdateException e)
     {
         string message = e.Message;
         if (e.InnerException != null)
         {
             message += Environment.NewLine;
             message += "Inner exception:";
             message += Environment.NewLine;
             message += e.InnerException;
             return(message);
         }
     }
     return("Your order is successfuly saved.");
 }
Exemplo n.º 6
0
 public bool Add(ProductCategory t)
 {
     _shoppingCartDbContext.Add(t);
     _shoppingCartDbContext.SaveChanges();
     return(true);
 }