Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        //[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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 6
0
        //[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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 8
0
 public ActionResult CreateModel(Menu Model)
 {
     try
     {
         db.Menu.Add(Model);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         throw;
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 15
0
 public long InsertFeedBack(Feedback fb)
 {
     try
     {
         db.Feedback.Add(fb);
         db.SaveChanges();
         return(fb.ID);
     }
     catch (Exception ex)
     {
     }
     return(-1);
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 21
0
 public long Insert(Order order)
 {
     db.Order.Add(order);
     db.SaveChanges();
     return(order.ID);
 }
Ejemplo n.º 22
0
 public void AddOrUpdate(Category element)
 {
     db.Category.AddOrUpdate(element);
     db.SaveChanges();
 }
Ejemplo n.º 23
0
 public void AddOrUpdate(Manufacturer element)
 {
     db.Manufacturer.AddOrUpdate(element);
     db.SaveChanges();
 }
Ejemplo n.º 24
0
 public void AddOrUpdate(Good element)
 {
     db.Good.AddOrUpdate(element);
     db.SaveChanges();
 }
Ejemplo n.º 25
0
 public void DeleteCartItem(CartItem item)
 {
     db.CartItems.Remove(item);
     db.SaveChanges();
 }
Ejemplo n.º 26
0
 public void AddProduct(Product product)
 {
     db.Products.Add(product);
     db.SaveChanges();
 }