Exemplo n.º 1
0
        private void BtnAddCategory_Click(object sender, EventArgs e)
        {
            string categoryName = txtCategoryName.Text;

            if (categoryName != string.Empty)
            {
                if (db.Categories.Any(ct => ct.Name == categoryName))
                {
                    lblError.Text    = "Dear Admin.Yeke oglansin bu adda category adi db'da var ";
                    lblError.Visible = true;
                }
                else
                {
                    db.Categories.Add(new Category
                    {
                        Name = categoryName
                    });
                    db.SaveChanges();
                    MessageBox.Show("Category Name was successfully created", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FillDgCategories();
                }
            }
            else
            {
                lblError.Text    = "Category name is not empty";
                lblError.Visible = true;
            }
        }
Exemplo n.º 2
0
 //新增商品方法
 public void Insert(Item newData)
 {
     //將資料加入資料庫實體
     db.Item.Add(newData);
     //儲存資料庫變更
     db.SaveChanges();
 }
        public IHttpActionResult PostFavoriteCategory([FromUri] Guid userId, [FromUri] Guid categoryId)
        {
            var user     = shoppingEntities.Users.FirstOrDefault(t => t.Id == userId);
            var category = shoppingEntities.Categories.FirstOrDefault(t => t.Id == categoryId);

            if (user == null)
            {
                throw new BadRequestException("User khong ton tai");
            }

            if (category == null)
            {
                throw new BadRequestException("Category khong ton tai");
            }

            if (shoppingEntities.FavoriteCategories.FirstOrDefault(t => t.UserId == user.Id && t.CategoryId == category.Id) == null)
            {
                FavoriteCategory favoriteCategory = new FavoriteCategory();
                favoriteCategory.Id       = Guid.NewGuid();
                favoriteCategory.Category = category;
                favoriteCategory.User     = user;
                shoppingEntities.FavoriteCategories.Add(favoriteCategory);

                shoppingEntities.SaveChanges();
            }


            return(Ok(new CategoryDto(category)));
        }
Exemplo n.º 4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            string name = txtName.Text;
            string price = txtPrice.Text;
            string category = cmbCategory.Text;
            string type = cmbTypes.Text;

            if (name == string.Empty || price == string.Empty || category == string.Empty || type == string.Empty)
            {
                lblError.Text = "Bosluq buraxmayin";
                return;
            }

            if(!decimal.TryParse(price,out decimal Price))
            {
                lblError.Text = "Qiymeti duzgun yazin";
                return;
            }

            Model.Product prt = new Model.Product
            {
                Name = name,
                Price = Price,
                CategoryId = Convert.ToInt32(category.Split('-')[0]),
                TypeId = Convert.ToInt32(type.Split('-')[0]),
            };
            db.Products.Add(prt);
            db.SaveChanges();
            Reset();
        }
Exemplo n.º 5
0
        public IHttpActionResult Post([FromBody] RoleDto roleDto)
        {
            Role role = roleDto.ToModel();

            shoppingEntities.Roles.Add(role);
            shoppingEntities.SaveChanges();

            return(Ok(new RoleDto(role)));
        }
Exemplo n.º 6
0
 //註冊新會員方法
 public void Register(Member newMember)
 {
     //將密碼Hash過
     newMember.Password = HashPassword(newMember.Password);
     //將資料加入資料庫實體
     db.Member.Add(newMember);
     //儲存資料庫變更
     db.SaveChanges();
 }
Exemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "ID,Nome,Latitude,Longitude")] Loja loja)
 {
     if (ModelState.IsValid)
     {
         db.Entry(loja).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(loja));
 }
Exemplo n.º 8
0
        public IHttpActionResult Post([FromBody] ShopDto shopDto)
        {
            var shop = shopDto.ToModel();

            shop.CreatedDate = System.DateTime.Now;

            shoppingEntities.Shops.Add(shop);
            shoppingEntities.SaveChanges();

            return(Ok(new ShopDto(shop)));
        }
Exemplo n.º 9
0
        public ActionResult Edit(Sale model)
        {
            int      id         = model.Id;
            int      productid  = model.ProductId;
            int      customerid = model.CustomerId;
            int      storeid    = model.StoreId;
            DateTime saledate   = model.SaleDate;
            string   msg;

            if (id == 0)
            {  // New Record
                try
                {
                    var sale = db.Set <Sale>();
                    sale.Add(new Sale {
                        Id         = id,
                        ProductId  = productid,
                        CustomerId = customerid,
                        StoreId    = storeid,
                        SaleDate   = saledate
                    });
                    db.SaveChanges();
                    msg = "New record created.";
                } catch (Exception)
                {
                    msg = "Cannot save new record. Contact the administrator.";
                }
            }
            else
            { // Existing Record
                var sale = db.Sales.Find(id);
                if (sale == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    try
                    {
                        sale.ProductId  = productid;
                        sale.CustomerId = customerid;
                        sale.SaleDate   = saledate;
                        db.SaveChanges();
                        msg = String.Format("Changes to record {0} have been saved.", id);
                    } catch (Exception)
                    {
                        msg = "Changes cannot be saved. Contact the administrator";
                    }
                }
            }
            var result = new { success = "True", Message = msg };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "ShoppingID,ShoppingName,Address,Phone")] Shopping shopping)
        {
            if (ModelState.IsValid)
            {
                db.Shoppings.Add(shopping);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(shopping));
        }
Exemplo n.º 11
0
        public bool DeleteOne(int id)
        {
            var item = Context.OrderDetails.Where(e => e.ODID == id).FirstOrDefault();

            if (item.Equals(null))
            {
                return(false);
            }
            Context.OrderDetails.Remove(item);
            Context.SaveChanges();
            return(true);
        }
Exemplo n.º 12
0
        public ActionResult Create([Bind(Include = "ID,CategoriaID,Nome,Unidade,QtdNormal,MarcasSim,MarcasNao,ListaPadrao")] Produto produto)
        {
            if (ModelState.IsValid)
            {
                db.Produtos.Add(produto);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoriaID = new SelectList(db.Categorias, "ID", "Nome", produto.CategoriaID);
            return(View(produto));
        }
        public ActionResult Create([Bind(Include = "ProductID,Name,Price,Description,ImageURL,CategoryID")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CName", product.CategoryID);
            return(View(product));
        }
Exemplo n.º 14
0
        //將商品放入購物車方法
        public void AddtoCart(string Cart, int Item_Id)
        {
            //宣告一筆新的CartBuy資料表資料物件
            CartBuy newData = new CartBuy();

            //設定資料的值
            newData.Cart_Id = Cart;
            newData.Item_Id = Item_Id;
            //將資料加入資料庫實體
            db.CartBuy.Add(newData);
            //儲存資料庫變更
            db.SaveChanges();
        }
Exemplo n.º 15
0
        public ActionResult Edit(ProductViewModel model)
        {
            string  msg;
            int     id    = model.Id;
            string  name  = model.ProductName;
            decimal?price = model.ProductPrice;

            if (id == 0) // New Record
            {
                try
                {
                    var newprod = db.Set <Product>();
                    newprod.Add(new Product {
                        Id = id, ProductName = name, ProductPrice = price
                    });
                    db.SaveChanges();
                    msg = "New record has been created";
                }
                catch (Exception)
                {
                    msg = "Unable to save new record. Contact the administrator.";
                }
            }
            else   // Existing record
            {
                var editproduct = db.Products.Find(id);
                if (editproduct == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    try
                    {
                        editproduct.ProductName  = name;
                        editproduct.ProductPrice = price;
                        db.SaveChanges();
                        msg = String.Format("Changes for record {0} have been saved", id);
                    } catch (Exception)
                    {
                        msg = String.Format("Unable to save changes to {0}. Contact the administrator.", id);
                    }
                }
            }
            var result = new { Success = "True", Message = msg };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 16
0
        public ActionResult Edit(Sale model)
        {
            string msg;

            if (model.Id == 0)
            { // new record
                var sale = new Sale();
                sale.ProductId  = model.ProductId;
                sale.CustomerId = model.CustomerId;
                sale.StoreId    = model.StoreId;
                sale.SaleDate   = model.SaleDate;
                try
                {
                    db.Sales.Add(sale);
                    db.SaveChanges();
                    msg = "New record created.";
                } catch (Exception)
                {
                    msg = "Unable to save changes. Contact the administrator.";
                }
            }
            else
            {
                var sale = db.Sales.Find(model.Id);
                if (sale == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    try {
                        sale.ProductId  = model.ProductId;
                        sale.CustomerId = model.CustomerId;
                        sale.StoreId    = model.StoreId;
                        sale.SaleDate   = model.SaleDate;
                        db.SaveChanges();
                        msg = String.Format("Changes to record {0} have been saved.", model.Id);
                    }
                    catch (Exception)
                    {
                        msg = "Unable to save changes. Contact the administrator.";
                    }
                }
            }
            var result = new { Message = msg };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 17
0
        private ActionResult ListaAbrirFechar(int?id, bool abrir)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var lista = db.Listas.Find(id);

            if (lista == null)
            {
                return(HttpNotFound());
            }
            lista.Aberta = abrir;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 18
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode,
                                  StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(order));
                }
                else
                {
                    //order.EmployeeId = User.Identity.;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    storeDB.Orders.Add(order);
                    storeDB.SaveChanges();
                    //Process the order
                    var cart = Models.ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order);

                    return(RedirectToAction("Complete",
                                            new { id = order.OrderId }));
                }
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
Exemplo n.º 19
0
        public ActionResult UpdateProduct(Product p)
        {
            WebImage photo          = null;
            var      newFileName    = "";
            var      imagePath      = "";
            var      imageThumbPath = "";

            photo = WebImage.GetImageFromRequest();
            if (photo != null)
            {
                newFileName = Path.GetFileName(photo.FileName);
                imagePath   = @"images/Products/" + newFileName;
                photo.Save(@"~/" + imagePath);
                imageThumbPath = @"images/Products/thumbnails/" + newFileName;
                photo.Resize(width: 165, height: 35, preserveAspectRatio: false, preventEnlarge: true);
                photo.Save(@"~/" + imageThumbPath);
            }
            var db  = new ShoppingEntities();
            var im  = "/" + imagePath;
            var im1 = "/" + imageThumbPath;

            p.Img             = im;
            p.Thumbnail       = im1;
            db.Entry(p).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("ListProducts"));
        }
Exemplo n.º 20
0
        //管理员删除产品操作
        public ActionResult Delete(String id)
        {
            //1、检查参数id的合法性  string -> int
            int productId;

            if (!int.TryParse(id, out productId))
            {
                return(Content("<script>alert('参数不合法');window.location.href='/AdminProduct/Index'</script>"));
            }
            //2、使用EF删除产品
            using (ShoppingEntities dc = new ShoppingEntities())
            {
                //1、先查询
                Product entity = dc.Product.FirstOrDefault(p => p.ProID == productId);
                //2、后删除
                dc.Product.Remove(entity);
                //3、保存回数据库中
                if (dc.SaveChanges() > 0)
                {
                    return(Content("<script>alert('产品下架成功!');window.location.href='/AdminProduct/Index'</script>"));
                }
                else
                {
                    return(Content("<script>alert('产品下载失败!');window.location.href='/AdminProduct/Index'</script>"));
                }
            }
        }
Exemplo n.º 21
0
        public ActionResult Submit(int id)
        {
            //1. 登录判断
            if (!IsLogined())
            {
                return(Content("<script>alert('请登录');window.location.href='/Users/Login'</script>"));
            }

            //往数据库的表中修改内容
            using (ShoppingEntities se = new ShoppingEntities())
            {
                string      text  = Request.Form["text"];
                TradeRecord order = se.TradeRecord.FirstOrDefault(u => u.TraPID == id);
                //判断是否提交过评论
                if (order.TraComment == null)
                {
                    var entry = se.Entry(order);
                    entry.State = System.Data.EntityState.Unchanged;
                    entry.Property("TraComment").IsModified = true;
                    order.TraComment = text;
                    if (se.SaveChanges() > 0)
                    {
                        return(Content("<script>alert('提价评价成功!');window.location.href='/Order/Index';</script>"));
                    }
                    else
                    {
                        return(Content("<script>alert('提价评价失败!');window.location.href='/Order/Index';</script>"));
                    }
                }
                else
                {
                    return(Content("<script>alert('已经提交过评论了,请勿重复提交!');window.location.href='/Order/Index';</script>"));
                }
            }
        }
Exemplo n.º 22
0
        private void BtnAddCategory_Click(object sender, EventArgs e)
        {
            string categoryName = txtCategoryName.Text;

            if (categoryName != string.Empty)
            {
                if (db.Category.Any(c => c.Name == categoryName))
                {
                    lblError.Text    = "Admin yeke oglansan .Bu adda category var.Agresivik!!!";
                    lblError.Visible = true;
                }
                else
                {
                    db.Category.Add(new Category
                    {
                        Name = categoryName
                    });
                    db.SaveChanges();
                    MessageBox.Show("Category ugurla əlavə olundu");
                    FillDgcategories();
                }
            }
            else
            {
                lblError.Text    = "Boş gonderme brat!";
                lblError.Visible = true;
            }
        }
 public IHttpActionResult CompleteOrder(int OrderID)
 {
     if (OrderDataValidation.ValidateOpenOrder(OrderID))
     {
         if (!CartDataValidation.ValidateEmptyCart(OrderID))
         {
             using (ShoppingEntities entity = new ShoppingEntities())
             {
                 using (ShoppingDiscount total = new ShoppingDiscount())
                 {
                     entity.Orders.First(o => o.O_ID == OrderID).O_TotalAmount = total.TotalAfterDiscount(OrderID);
                     entity.Orders.First(o => o.O_ID == OrderID).O_Status      = ShoppingData.CloseOrderStatus;
                     entity.SaveChanges();
                     return(Ok("Total Amount after Discount = " + total.TotalAfterDiscount(OrderID)));
                 }
             }
         }
         else
         {
             return(BadRequest("There is no item in cart"));
         }
     }
     else
     {
         return(BadRequest("Invalid OrderID"));
     }
 }
Exemplo n.º 24
0
 public ActionResult Edit(StoreViewModel model)
 {
     if (ModelState.IsValid)
     {
         var store = db.Stores.Find(model.Id);
         store.StoreName    = model.StoreName;
         store.StoreAddress = model.StoreAddress;
         db.SaveChanges();
         TempData["Message"] = "Changes have been saved.";
         return(RedirectToAction("Index"));
     }
     else
     {
         TempData["Message"] = "Unable to save changes. Contact the administrator.";
         return(RedirectToAction("Index"));
     }
 }
Exemplo n.º 25
0
        public ActionResult Edit(CustomerViewModel model)
        {
            int    id      = model.Id;
            string name    = model.CustomerName;
            string address = model.CustomerAddress;
            string msg     = "";

            if (id == 0)
            { // New record
                try {
                    var customer = new Customer()
                    {
                        CustomerName    = name,
                        CustomerAddress = address
                    };
                    db.Customers.Add(customer);
                    db.SaveChanges();
                    msg = "New record created.";
                } catch (Exception)
                {
                    msg = "Unable to create new record. Contact the adminstrator";
                }
            }
            else
            { // Existing record
                var customer = db.Customers.Find(id);
                if (customer == null)
                {
                    return(HttpNotFound());
                }
                try
                {
                    customer.CustomerName    = name;
                    customer.CustomerAddress = address;
                    db.SaveChanges();
                    msg = string.Format("Changes to {0} have been saved.", id);
                }
                catch (Exception)
                {
                    msg = string.Format("Unable to save changes to {0}. Contact the administrator.", id);
                }
            }
            var result = new { success = "True", Message = msg };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 26
0
 public ActionResult Edit(ProductViewModel model)
 {
     if (ModelState.IsValid)
     {
         var product = db.Products.Find(model.Id);
         product.ProductName  = model.ProductName;
         product.ProductPrice = model.ProductPrice;
         db.SaveChanges();
         TempData["Message"] = "Product has been changed";
         return(RedirectToAction("Index"));
     }
     else
     {
         TempData["Message"] = "Unable to edit record. Contact the administrator";
         return(RedirectToAction("Index"));
     }
 }
Exemplo n.º 27
0
        public ActionResult Edit(ProductViewModel model)
        {
            string msg;

            if (model.Id == 0) // new record
            {
                try
                {
                    var newproduct = new Product()
                    {
                        ProductName  = model.ProductName,
                        ProductPrice = model.ProductPrice
                    };
                    db.Products.Add(newproduct);
                    db.SaveChanges();
                    msg = "New record created";
                }
                catch (Exception)
                {
                    msg = "Unable to created new record. Contact the administrator.";
                }
            }
            else
            {
                var product = db.Products.Find(model.Id);
                if (product == null)
                {
                    return(HttpNotFound());
                }
                try
                {
                    product.ProductName  = model.ProductName;
                    product.ProductPrice = model.ProductPrice;
                    db.SaveChanges();
                    msg = String.Format("Changes to {0} have been saved.", model.Id);
                }
                catch (Exception)
                {
                    msg = String.Format("Unable save changes for {0}. Contact the administrator", model.Id);
                }
            }
            var result = new { Message = msg };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 28
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            string productName = txtProName.Text;
            string price       = txtPrice.Text;
            string comboName   = cmbCatName.Text;
            int    productPrice;

            if (productName != string.Empty && price != string.Empty)
            {
                if (int.TryParse(price, out productPrice))
                {
                    lblError.Visible = false;
                    if (db.Products.Any(pro => pro.Name == productName))
                    {
                        lblError.Visible = true;
                        lblError.Text    = "This Product has already been exsist in Database";
                    }
                    else
                    {
                        int selectedcategory = db.Categories.FirstOrDefault(sc => sc.Name == comboName).Id;
                        MessageBox.Show(selectedcategory.ToString());

                        db.Products.Add(new Product
                        {
                            Name        = productName,
                            Category_id = selectedcategory,
                            Price       = productPrice
                        });
                        db.SaveChanges();
                        MessageBox.Show("Product have been added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        FillDtgProduct();
                    }
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = "Please enter number";
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = "Please field all input";
            }
        }
Exemplo n.º 29
0
        public ActionResult DeleteConfirmed(int id)
        {
            var     db = new ShoppingEntities();
            Product p  = db.Products.Find(id);

            db.Products.Remove(p);
            db.SaveChanges();
            return(RedirectToAction("ListProducts"));
        }
Exemplo n.º 30
0
        private void Button1_Click(object sender, EventArgs e)
        {
            string firstname      = txtFirstName.Text;
            string lastname       = txtLastName.Text;
            string email          = txtEmail.Text;
            string password       = txtPassword.Text;
            string repeatpassword = txtRepeat.Text;
            string phone          = txtPhone.Text;
            bool   allEmpty       = Extensions.isNotEmpty(new string[] {
                firstname, lastname, email, repeatpassword, phone, password
            }, String.Empty);

            if (allEmpty)
            {
                lblError.Visible = false;

                if (password.Length >= 8)
                {
                    if (password == repeatpassword)
                    {
                        Customers cusEmail = db.Customers.FirstOrDefault(a => a.Email == email);
                        if (cusEmail == null)
                        {
                            Customers cus = new Customers();
                            cus.Firstname = firstname;
                            cus.Surname   = lastname;
                            cus.Email     = email;
                            cus.Phone     = phone;
                            cus.Password  = password.hashMe();
                            db.Customers.Add(cus);
                            db.SaveChanges();
                            MessageBox.Show(firstname + " " + lastname + " was created successfully", "Custumer Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            lblError.Visible = true;
                            lblError.Text    = "Email already exsist";
                        }
                    }
                    else
                    {
                        lblError.Visible = true;
                        lblError.Text    = "Password and Repeat password does not contain";
                    }
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = "Password should be long 8 charachter";
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = "Please,field input";
            }
        }