Exemple #1
0
        public Cart AddProductToCart(Cart cart)
        {
            cart.DateofOrder = DateTime.Now;
            var isExists = IsProductExists(cart.ProductName);

            Details orderDetail = new Details();

            if (isExists)
            {
                Cart ct = new Cart();



                var prodId = _db.Carts.Where(cName => cName.ProductName == cart.ProductName).FirstOrDefault();



                var cartId = _db.Carts.Where(cName => cName.ProductName == cart.ProductName).Select(cName => cName.ProductId).Single();

                prodId.Quantity = prodId.Quantity + cart.Quantity;
                prodId.Price    = cart.Price;


                var detailProdId = _db.Details.Where(cName => cName.ProductName == cart.ProductName).FirstOrDefault();

                detailProdId.Quantity = detailProdId.Quantity + cart.Quantity;

                detailProdId.Price = cart.Price;


                _db.SaveChanges();
                return(ct);
            }

            else
            {
                //if (cart.Quantity == 0)
                //{
                //    cart.Quantity++;
                //}
                _db.Carts.Add(cart);
                _db.SaveChanges();

                orderDetail.Price        = cart.Price;
                orderDetail.ProductId    = cart.ProductId;
                orderDetail.ProductImage = cart.ProductImage;
                orderDetail.ProductName  = cart.ProductName;
                orderDetail.Quantity     = cart.Quantity;
                orderDetail.CustomerId   = cart.CustomerId;
                orderDetail.DateofOrder  = cart.DateofOrder;
                orderDetail.Amount       = cart.Amount;

                _db.Details.Add(orderDetail);
                _db.SaveChanges();

                return(cart);
            }
        }
Exemple #2
0
        public Order PlaceOrder(Order order)
        {
            var orderTable = new Order();


            if (order != null)
            {
                orderTable.OrderDate  = DateTime.Now;
                orderTable.CustomerId = order.CustomerId;
                orderTable.AddressId  = order.AddressId;
                orderTable.Amount     = order.Amount;


                _db.Orders.Add(orderTable);
                _db.SaveChanges();



                if (order != null)
                {
                    var getOrderId = _db.Orders.Where(cId => cId.CustomerId == order.CustomerId).Select(oId => oId.Id).LastOrDefault();
                    var detailRow  = _db.Details.Where(cId => cId.CustomerId == order.CustomerId).Select(oId => oId.OrderId).ToList();

                    using (MajesticDbContext db = new MajesticDbContext())
                    {
                        db.Details.Where(x => x.CustomerId == order.CustomerId).ToList().ForEach(x =>
                        {
                            x.OrderId = getOrderId;
                        });
                        db.SaveChanges();
                    }
                    if (order != null)
                    {
                        _db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Carts]");
                        _db.SaveChanges();
                    }

                    //for (int i = 0; i < _db.Details.Count(); i++)
                    //{
                    //    detailRow.Add(getOrderId);

                    //}
                    //_db.SaveChanges();
                }
            }


            return(orderTable);
        }
Exemple #3
0
        public Product AddProduct(Product item)
        {
            var category = new Category();

            var isExists = IsCategoryExists(item.CategoryName.ToUpper());

            var catName = item.CategoryName.ToUpper();

            if (isExists)
            {
                var catId = _db.Categories.Where(cName => cName.CategoryName == catName).Select(cName => cName.CategoryId).Single();

                item.CategoryId = catId;

                _db.Products.Add(item);
                _db.SaveChanges();
                return(item);
            }

            else
            {
                category.CategoryName = item.CategoryName.ToUpper();


                _db.Categories.Add(category);
                _db.SaveChanges();

                var catId = _db.Categories.Where(cName => cName.CategoryName == catName).Select(cName => cName.CategoryId).Single();

                item.CategoryId = catId;
                _db.Products.Add(item);
                _db.SaveChanges();



                return(item);
            }
        }
        public Address AddAddress(Address address)
        {
            var IsExists = IsAddressExists(address.StreetAddress, address.City, address.PinCode);

            if (address != null)
            {
                address.AddressType   = address.AddressType.ToUpper();
                address.City          = address.City.ToUpper();
                address.State         = address.State.ToUpper();
                address.StreetAddress = address.StreetAddress.ToUpper();
                address.FullName      = address.FullName.ToUpper();

                _db.Addresses.Add(address);
                _db.SaveChanges();
                return(address);
            }



            return(address);
        }