示例#1
0
        public ActionResult Checkout(Purchase purchase)
        {
            List <CartItem> cartItems = db.CartItems.Where(x => x.CartId == 1).ToList();

            purchase.PurchasePrice = cartItems.Sum(x => x.CartItemPrice);
            purchase.Date          = DateTime.Now;

            if (cartItems.Count == 0)
            {
                ModelState.AddModelError("", "У вас должны быть товары для покупки");
            }

            if (ModelState.IsValid)
            {
                db.Purchases.Add(purchase);
                db.SaveChanges();

                for (int i = 0; i < cartItems.Count; i++)
                {
                    db.PurchaseDetails.Add(new PurchaseDetails {
                        ProductId  = cartItems[i].ProductId,
                        PurchaseId = purchase.PurchaseId
                    });
                    db.SaveChanges();

                    db.CartItems.Remove(cartItems[i]);
                    db.SaveChanges();
                }

                return(RedirectToAction("Complete"));
            }

            return(View(purchase));
        }
        public void AddItem(string itemName, int itemAmount, double itemPrice)
        {
            var newItem = new Product()
            {
                Name = itemName, Amount = itemAmount, Value = itemPrice
            };

            shopDB.products.Add(newItem);
            shopDB.SaveChanges();
        }
        //[ValidateAntiForgeryToken]
        public JsonResult Create([Bind(Include = "Id,Name,Adress")] Shop shop)
        {
            if (ModelState.IsValid)
            {
                db.Shops.Add(shop);
                db.SaveChanges();
                return(Json(true));
            }

            return(Json(false));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "ID,UserName,Password,GroupID,Name,Address,Email,Phone,ProvinceID,DistrictID,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Status,roleID,img")] User user)
        {
            if (ModelState.IsValid)
            {
                db.User.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
示例#5
0
 public ActionResult Edit([Bind(Include = "ID,Name,MetaTitle,ParentID,DisplayOrder,SeoTitle,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,ShowOnHome,Language")] Category category)
 {
     SetViewBag(category.ID);
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
        //[ValidateAntiForgeryToken]
        public JsonResult Create([Bind(Include = "Id,Name,Specification,Price,ShopId")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return(Json(true));
            }

            ViewBag.ShopId = new SelectList(db.Shops, "Id", "Name", item.ShopId);
            return(Json(false));
        }
示例#7
0
        public ActionResult Create([Bind(Include = "ID,Name,MetaTitle,ParentID,DisplayOrder,SeoTitle,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,ShowOnHome")] ProductCategory productCategory)
        {
            if (ModelState.IsValid)
            {
                SetViewBag(productCategory.ParentID);
                db.ProductCategory.Add(productCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productCategory));
        }
示例#8
0
 public ActionResult CreateModel(Menu Model)
 {
     try
     {
         db.Menu.Add(Model);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         throw;
     }
     return(RedirectToAction("Index"));
 }
示例#9
0
 public bool?ChangeStatus(long id)
 {
     try
     {
         var user = db.User.Find(id);
         user.Status = !user.Status;
         db.SaveChanges();
         return(user.Status);
     }
     catch (Exception ex)
     {
     }
     return(null);
 }
示例#10
0
        private void button1_Click(object sender, EventArgs e)
        {
            string productName = txtProduct.Text;
            string price       = txtPrice.Text;
            string Amount      = txtAmount.Text;
            string Category    = cmbCategory.Text;
            string Size        = cmbSize.Text;
            string Desc        = rcDescription.Text;

            string[] emp = { productName, price, Amount, Category, Size, };

            if (mainExtensions.IsEmpty(emp, string.Empty))
            {
                int CatId  = db.Categories.First(ct => ct.Name == Category).Id;
                int SizeId = db.ProductSizes.First(ct => ct.Size == Size).Id;

                db.Products.Add(new Product()
                {
                    ProductName = productName,
                    Price       = Convert.ToDouble(price),
                    Amount      = Convert.ToInt32(Amount),
                    CategoryId  = CatId,
                    SizeId      = SizeId,
                });
                db.SaveChanges();
                MessageBox.Show("Product create successfully", "success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
            }
            NewProduct np = new NewProduct();

            np.ShowDialog();
        }
示例#11
0
        public ActionResult EditPut(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopDB db = new ShopDB();
            var    productToUpdate = db.Products.Find(id);

            if (TryUpdateModel(productToUpdate, "",
                               new string[] { "ProductName", "ProductPrice", "ProductDescription", "ProductImg", "CategoryId" }))
            {
                try
                {
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception dex)
                {
                    db.Logs.Add(new Log {
                        LogDesc = dex.ToString()
                    });
                }
            }
            return(View(productToUpdate));
        }
示例#12
0
        // GET: Admin/Orders/Payments/5
        public ActionResult Payments(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Order order = db.Order.Find(id);

            if (order == null)
            {
                return(HttpNotFound());
            }
            order.Ship = DateTime.Now;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#13
0
        public ActionResult Create([Bind(Include = "ID,Name,Code,MetaTitle,Description,Image,MoreImages,Price,PromotionPrice,IncludedVAT,Quantity,CategoryID,Detail,Warranty,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescriptions,Status,TopHot,ViewCount")] Product product, HttpPostedFileBase file)
        {
            if (file != null)
            {
                file.SaveAs(HttpContext.Server.MapPath("~/assets/Admin/images/")
                            + file.FileName);
                product.Image = "/assets/Admin/images/" + file.FileName;
            }
            SetViewBag(product.CategoryID);
            if (ModelState.IsValid)
            {
                db.Product.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
示例#14
0
 public ActionResult Create(Product product, HttpPostedFileBase image1, HttpPostedFileBase image2)
 {
     if (ModelState.IsValid)
     {
         if (image1 != null)
         {
             product.Image = new byte[image1.ContentLength];
             image1.InputStream.Read(product.Image, 0, image1.ContentLength);
         }
         if (image2 != null)
         {
             product.ImageSmall = new byte[image2.ContentLength];
             image2.InputStream.Read(product.ImageSmall, 0, image2.ContentLength);
         }
         _db.Product.Add(product);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
示例#15
0
 public long InsertFeedBack(Feedback fb)
 {
     try
     {
         db.Feedback.Add(fb);
         db.SaveChanges();
         return(fb.ID);
     }
     catch (Exception ex)
     {
     }
     return(-1);
 }
示例#16
0
 public bool update(long id, int Quantity)
 {
     try
     {
         var results = db.Product.Find(id);
         results.Quantity = results.Quantity - Quantity;
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
示例#17
0
 public bool Delete(long ID)
 {
     try
     {
         var obj = db.Menu.Where(x => x.ID == ID).FirstOrDefault();
         db.Menu.Remove(obj);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#18
0
 public ActionResult Create(Images img, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         if (file != null)
         {
             file.SaveAs(HttpContext.Server.MapPath("~/assets/Admin/images/")
                         + file.FileName);
             img.Name = file.FileName;
         }
         db.Images.Add(img);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(img));
 }
示例#19
0
        //private void ClearRegisterInput()
        //{
        //    txtFullname.Text = "";
        //    txtEmail.Text = "";
        //    txtPassword.Text = "";
        //    txtConfirmPassword.Text = "";
        //    txtPhone.Text = "";

        //}
        private void BtnRegister_Click(object sender, EventArgs e)
        {
            string fullname = txtFullname.Text;

            string email           = txtEmail.Text;
            string password        = txtPassword.Text;
            string phone           = txtPhone.Text;
            string confirmPassword = txtConfirmPassword.Text;

            if (fullname != "" && email != "" && password != "" && phone != "" &&
                confirmPassword != "")
            {
                if (password == confirmPassword)
                {
                    if (password.Length >= 5)
                    {
                        db.Clients.Add(new Client {
                            Email    = email,
                            Password = password.HashMe(),
                            Phone    = phone,
                            Fullname = fullname
                        });
                        db.SaveChanges();
                        MessageBox.Show(fullname + " was successfully created", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Login lg = new Login();
                        this.Close();
                        lg.ShowDialog();
                    }
                    else
                    {
                        lblError.Text    = "Password length should be greater than 5";
                        lblError.Visible = true;
                    }
                }
                else
                {
                    lblError.Text    = "Password and Confirm Password must be same!";
                    lblError.Visible = true;
                }
            }
            else
            {
                lblError.Text    = "Please all the Fill!";
                lblError.Visible = true;
            }
        }
示例#20
0
        private void Button1_Click(object sender, EventArgs e)
        {
            string  productname   = cmbProduct.Text;
            string  categoryname  = cmbCategory.Text;
            Product selectProduct = _db.Products.FirstOrDefault(pr => pr.Name == productname);
            double  price         = (double)selectProduct.Price * (double)nmCount.Value;

            _db.Orders.Add(new Order
            {
                ClientId     = activeClient.Id,
                ProductId    = selectProduct.Id,
                PurchaseDate = DateTime.Now,
                Amount       = (int)nmCount.Value,
                Price        = price
            });
            _db.SaveChanges();
            MessageBox.Show(productname + " " + nmCount.Value + " ədəd aldınız!", "Orders", MessageBoxButtons.OK, MessageBoxIcon.Information);
            ProductGridBuyView();
        }
示例#21
0
 public long Insert(Order order)
 {
     db.Order.Add(order);
     db.SaveChanges();
     return(order.ID);
 }
示例#22
0
 public void AddOrUpdate(Category element)
 {
     db.Category.AddOrUpdate(element);
     db.SaveChanges();
 }
示例#23
0
 public void AddOrUpdate(Manufacturer element)
 {
     db.Manufacturer.AddOrUpdate(element);
     db.SaveChanges();
 }
示例#24
0
 public void AddOrUpdate(Good element)
 {
     db.Good.AddOrUpdate(element);
     db.SaveChanges();
 }
示例#25
0
 public void DeleteCartItem(CartItem item)
 {
     db.CartItems.Remove(item);
     db.SaveChanges();
 }
示例#26
0
 public void AddProduct(Product product)
 {
     db.Products.Add(product);
     db.SaveChanges();
 }