public int PlaceOrder(OrderFinalDetails details)
        {
            Ordertable order = new Ordertable();

            order.TotalAmount = details.TotalAmount;
            order.CustomerId  = details.Cid;
            order.OrderDate   = DateTime.Now;
            order.CategoryId  = details.Products[0].CategoryId;

            context.Ordertable.Add(order);
            context.SaveChanges();
            //~~~~~~~~~~~~~~~~~~OrderDetails table~~~~~~~~~~~~~~~~~~~~~~

            Orderdetails[] products = new Orderdetails[details.Products.Length];
            for (var i = 0; i < details.Products.Length; i++)
            {
                products[i] = new Orderdetails()
                {
                    OrderId   = order.OrderId,
                    Price     = details.Products[i].Price,
                    Quantity  = details.Products[i].Quantity,
                    ProductId = details.Products[i].ProductId
                };
                // context.Orderdetails.Add(products[i]);
            }
            context.Orderdetails.AddRange(products);
            //~~~~~~~~~~~~~~~~~~~~~payment table~~~~~~~~~~~~~~~~~~~~~

            Payment payment = new Payment();

            payment = new Payment()
            {
                OrderId     = order.OrderId,
                Amount      = (decimal)order.TotalAmount.Value,
                PaymentDate = DateTime.Now,
                Mode        = details.PaymentMode
            };

            context.Payment.Add(payment);
            Product p;

            for (int i = 0; i < details.Products.Length; i++)
            {
                p           = context.Product.SingleOrDefault(c => c.ProductId == details.Products[i].ProductId);
                p.Quantity -= details.Products[i].Quantity;
            }

            context.SaveChanges();
            return(payment.InvoiceId);
        }
Beispiel #2
0
        public int SignUp(Customer customer)
        {
            context.Customer.Add(customer);
            int entry = context.SaveChanges();

            return(entry);
        }
        public ActionResult EditProduct(EditProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                var  product     = Db.Products.Find(model.ProductId);
                var  name        = product.ProductName;
                var  quantity    = product.Quantity;
                var  price       = product.Price;
                var  sale        = product.SalePrice;
                var  description = product.Description;
                bool isChanged   = false;
                if (!name.Equals(model.ProductName))
                {
                    product.ProductName = model.ProductName;
                    isChanged           = true;
                }

                if (!price.Equals(model.Price))
                {
                    product.Price = model.Price;
                    isChanged     = true;
                }
                if (!quantity.Equals(model.Quantity))
                {
                    product.Quantity = model.Quantity;
                    isChanged        = true;
                }
                if (!sale.Equals(model.SalePrice))
                {
                    product.SalePrice = model.SalePrice;
                    isChanged         = true;
                }

                if (!description.Equals(model.Description))
                {
                    product.Description = model.Description;
                    isChanged           = true;
                }


                if (isChanged)
                {
                    Db.SaveChanges();
                }
            }
            return(RedirectToAction("Index", "Product", new { id = model.ProductId }));
        }
 public static void CleanUp()
 {
     if (CustomerId != 0)
     {
         var customer = context.Customer.SingleOrDefault(c => c.CustomerId == CustomerId);
         context.Customer.Remove(customer);
         context.SaveChanges();
     }
 }
 public bool CreateUserAccount(SignUpViewModel account)
 {
     try
     {
         Db.Users.Add(new User
         {
             Username  = account.Username,
             Password  = account.Password,
             FirstName = account.FirstName,
             LastName  = account.LastName,
             Email     = account.Email
         });
         Db.SaveChanges();
     }
     catch (Exception e)
     {
         return(false);
     }
     return(true);
 }
Beispiel #6
0
        public int SignUp(Customer customer)
        {
            var result = (from c in context.Customer where c.Email == customer.Email select c).Any();
            var check  = result;

            if (check == false)
            {
                context.Customer.Add(customer);
                int entry = context.SaveChanges();
                return(entry);
            }

            return(0);
        }
 public void Save()
 {
     context.SaveChanges();
 }
Beispiel #8
0
 public void Save()
 {
     onlineShoppingDbContext.SaveChanges();
 }
Beispiel #9
0
 public void SaveCategoryToDb(Category category)
 {
     onlineShoppingDbContext.Categories.Add(category);
     onlineShoppingDbContext.SaveChanges();
 }
Beispiel #10
0
 public void StoreToCartDb(Cart Cart)
 {
     onlineShoppingDbContext.Carts.Add(Cart);
     onlineShoppingDbContext.SaveChanges();
 }
Beispiel #11
0
 public virtual void Commit()
 {
     _context.SaveChanges();
 }
 public void PlaceOrder(Order order)
 {
     onlineShoppingDbContext.Orders.Add(order);
     onlineShoppingDbContext.SaveChanges();
 }
Beispiel #13
0
 //public void AnyUser(User user, out bool email, out bool userName)
 //{
 //    email = onlineShoppingDbContext.Users.Any(x => x.UserEmail == user.UserEmail);
 //    userName = onlineShoppingDbContext.Users.Any(x => x.UserName == user.UserName);
 //}
 public void Create(User user)
 {
     onlineShoppingDbContext.Users.Add(user);
     onlineShoppingDbContext.SaveChanges();
 }
Beispiel #14
0
 public void ApproveOrder(Order order)
 {
     onlineShoppingDbContext.Entry(order).State = EntityState.Modified;
     onlineShoppingDbContext.SaveChanges();
 }