Ejemplo n.º 1
0
 public ActionResult AddOrEdit(UserViewModel sm)
 {
     using (WebDBEntities db = new WebDBEntities())
     {
         if (sm.userID == 0)
         {
             tbl_User tb = new tbl_User();
             tb.username = sm.username;
             tb.password = sm.password;
             tb.fullname = sm.fullname;
             tb.email    = sm.email;
             db.tbl_User.Add(tb);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             tbl_User tbm = db.tbl_User.Where(m => m.userID == sm.userID).FirstOrDefault();
             tbm.username = sm.username;
             tbm.password = sm.password;
             tbm.fullname = sm.fullname;
             tbm.email    = sm.email;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Ejemplo n.º 2
0
        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            int            newFGID;
            decimal        newPrice;
            WebDBEntities  db = new WebDBEntities();
            Finished_Goods fg = new Finished_Goods();

            if (priceBox.Text == 0.00.ToString("C") || !decimal.TryParse(priceBox.Text.Trim('$'), out newPrice) || newPrice <= 0)
            {
                errBox.Content = "Error: Please input a price that is greater than 0 and is numeric.";
                return;
            }
            if (descBox.Text == "")
            {
                errBox.Content = "Error: Please input a description.";
                return;
            }
            if (packBox.Text == "")
            {
                errBox.Content = "Error: Please input a package type.";
                return;
            }
            if (!int.TryParse(fgidBox.Text, out newFGID) || newFGID < 0)
            {
                errBox.Content = "Error: Please input an FGID that is numerical and greater than 0.";
                return;
            }
            fg.Price       = (double)newPrice;
            fg.FGID        = newFGID;
            fg.Description = descBox.Text;
            fg.Packaging   = packBox.Text;
            if (db.Finished_Goods.Find(newFGID) != null)
            {
                if (isNew)
                {
                    errBox.Content = "Error: There is already a product with that ID.";
                    return;
                }
                else
                {
                    // Delete current element based on its previous FGID
                    db.Finished_Goods.Remove(db.Finished_Goods.Find(db.Finished_Goods.ToArray().ElementAt(curPos).FGID));
                    db.SaveChanges();
                }
            }
            db.Finished_Goods.Add(fg);
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                errBox.Content = "Error: There is already a product with that ID.";
                return;
            }
            errBox.Content = "Item saved.";
        }
Ejemplo n.º 3
0
        public ActionResult AddOrEdit(ProductViewModel ivm)
        {
            using (WebDBEntities db = new WebDBEntities())
            {
                if (ivm.productID == 0)
                {
                    tbl_Product itm = new tbl_Product();

                    itm.categoryID   = Convert.ToInt32(ivm.categoryID);
                    itm.title        = ivm.title;
                    itm.unitPrice    = ivm.unitPrice;
                    itm.sellingPrice = ivm.sellingPrice;
                    itm.description  = ivm.description;
                    HttpPostedFileBase fup = Request.Files["photo"];
                    if (fup != null)
                    {
                        if (fup.FileName != "")
                        {
                            fup.SaveAs(Server.MapPath("~/ProductImages/" + fup.FileName));
                            itm.photo = fup.FileName;
                        }
                    }

                    itm.isSpecial = ivm.isSpecial;
                    db.tbl_Product.Add(itm);
                    db.SaveChanges();
                    ViewBag.Message = "Created Successfully";
                }
                else
                {
                    tbl_Product itm = db.tbl_Product.Where(i => i.productID == ivm.productID).FirstOrDefault();
                    itm.categoryID   = Convert.ToInt32(ivm.categoryID);
                    itm.title        = ivm.title;
                    itm.unitPrice    = ivm.unitPrice;
                    itm.sellingPrice = ivm.sellingPrice;
                    itm.description  = ivm.description;
                    HttpPostedFileBase fup = Request.Files["Photo"];
                    if (fup != null)
                    {
                        if (fup.FileName != "")
                        {
                            fup.SaveAs(Server.MapPath("~/ProductImages/" + fup.FileName));
                            itm.photo = fup.FileName;
                        }
                    }



                    db.SaveChanges();
                    ViewBag.Message = "Updated Successfully";
                }
                ViewBag.Categories = db.tbl_Category.ToList();
                return(View(new ProductViewModel()));
            }
        }
Ejemplo n.º 4
0
 public ActionResult AddOrEdit(tbl_Category sm)
 {
     using (WebDBEntities db = new WebDBEntities())
     {
         if (sm.categoryID == 0)
         {
             db.tbl_Category.Add(sm);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(sm).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Ejemplo n.º 5
0
        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            int           newRMID;
            decimal       newCost;
            WebDBEntities db = new WebDBEntities();
            Raw_Materials rm = new Raw_Materials();

            if (costBox.Text == 0.00.ToString("C") || !decimal.TryParse(costBox.Text.Trim('$'), out newCost) || newCost <= 0)
            {
                errBox.Content = "Error: Please input a cost that is greater than 0 and is numeric.";
                return;
            }
            if (descBox.Text == "")
            {
                errBox.Content = "Error: Please input a description.";
                return;
            }
            if (!int.TryParse(idBox.Text, out newRMID) || newRMID < 0)
            {
                errBox.Content = "Error: Please input an RMID that is numerical and greater than 0.";
                return;
            }
            rm.Cost        = newCost;
            rm.RMID        = newRMID;
            rm.Description = descBox.Text;
            if (db.Raw_Materials.Find(newRMID) != null)
            {
                if (isNew)
                {
                    errBox.Content = "Error: There is already a material with that ID.";
                    return;
                }
                else
                {
                    // Delete current element based on its previous RMID
                    db.Raw_Materials.Remove(db.Raw_Materials.Find(db.Raw_Materials.ToArray().ElementAt(curPos).RMID));
                    db.SaveChanges();
                }
            }
            db.Raw_Materials.Add(rm);
            db.SaveChanges();
            errBox.Content = "Item saved.";
        }
Ejemplo n.º 6
0
 public ActionResult Delete(int id)
 {
     using (WebDBEntities db = new WebDBEntities())
     {
         tbl_User sm = db.tbl_User.Where(x => x.userID == id).FirstOrDefault();
         db.tbl_User.Remove(sm);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 7
0
 public ActionResult ViewOrder_Post(int id)
 {
     using (WebDBEntities db = new WebDBEntities())
     {
         tbl_Order sm = db.tbl_Order.Where(x => x.orderID == id).FirstOrDefault();
         sm.delivayStatus = "Confirmed";
         db.SaveChanges();
         return(RedirectToAction("ManageOrder", "Order"));
     }
 }
Ejemplo n.º 8
0
        public ActionResult Signup(UserViewModel uvm)
        {
            tbl_User tb = new tbl_User();

            tb.username = uvm.username;
            tb.password = uvm.password;
            tb.email    = uvm.email;
            tb.fullname = uvm.fullname;
            _db.tbl_User.Add(tb);
            _db.SaveChanges();

            tbl_UserRole utb    = new tbl_UserRole();
            int          userID = tb.userID;
            int          roleID = 2;

            utb.userID = userID;
            utb.roleID = roleID;
            _db.tbl_UserRole.Add(utb);
            _db.SaveChanges();
            return(RedirectToAction("Login"));
        }
Ejemplo n.º 9
0
 public ActionResult AddOrEdit(CategoryViewModel sm)
 {
     using (WebDBEntities db = new WebDBEntities())
     {
         if (sm.categoryID == 0)
         {
             tbl_Category tb = new tbl_Category();
             tb.categoryName = sm.categoryName;
             db.tbl_Category.Add(tb);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             tbl_Category tbm = db.tbl_Category.Where(m => m.categoryID == sm.categoryID).FirstOrDefault();
             tbm.categoryName = sm.categoryName;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Ejemplo n.º 10
0
 // Xóa bản ghi bằng entity
 public bool DeleteArticle(int Id)
 {
     try
     {
         var at = db.Articles.Find(Id);
         db.Articles.Remove(at);
         db.SaveChanges();
         return(true);
     }catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 11
0
        public ActionResult Signup(UserViewModel uv)
        {
            tbl_User tbl = _db.tbl_User.Where(u => u.username == uv.username).FirstOrDefault();

            if (tbl != null)
            {
                return(Json(new { success = false, message = "User Already Register" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                tbl_User tb = new tbl_User();
                tb.username = uv.username;
                tb.password = uv.password;
                _db.tbl_User.Add(tb);
                _db.SaveChanges();

                tbl_UserRole ud = new tbl_UserRole();
                ud.userID     = tb.userID;
                ud.userroleID = 2;
                _db.tbl_UserRole.Add(ud);
                _db.SaveChanges();
                return(Json(new { success = true, message = "User Register Successfully" }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 12
0
        public ActionResult AddressAndPayment(OrderViewModel ovm)
        {
            var cart = ShoppingCart.GetCart(this.HttpContext);

            tbl_Order tb = new tbl_Order();

            tb.username      = Session["username"].ToString();
            tb.firstname     = ovm.firstname;
            tb.lastname      = ovm.lastname;
            tb.address       = ovm.address;
            tb.phone         = ovm.phone;
            tb.total         = cart.GetTotal();
            tb.orderDate     = Convert.ToDateTime(DateTime.Today.ToShortDateString());
            tb.delivayStatus = "Pending";

            storeDB.tbl_Order.Add(tb);
            storeDB.SaveChanges();


            List <tbl_Cart> lst = cart.GetCartItems();

            foreach (var item in lst)
            {
                tbl_OrderDetail tbord = new tbl_OrderDetail();
                tbord.orderID   = tb.orderID;
                tbord.productID = item.productID;
                tbord.quantity  = item.count;
                tbord.unitPrice = item.tbl_Product.sellingPrice;
                storeDB.tbl_OrderDetail.Add(tbord);
                storeDB.SaveChanges();
            }


            ViewBag.Message = "Your Ordered Done Successfully, It Takes 2/3 Hours In Our working Days";
            return(View());
        }
Ejemplo n.º 13
0
        private void delBtn_Click(object sender, RoutedEventArgs e)
        {
            WebDBEntities db = new WebDBEntities();
            Raw_Materials rm = new Raw_Materials();

            if (isNew)
            {
                idBox.Text     = 0000.ToString();
                descBox.Text   = "";
                costBox.Text   = "$0.00";
                errBox.Content = "";
                return;
            }
            else
            {
                db.Raw_Materials.Remove(db.Raw_Materials.Find(db.Raw_Materials.ToArray().ElementAt(curPos).RMID));
                db.SaveChanges();
                loadData(curPos);
                errBox.Content = "";
            }
        }
Ejemplo n.º 14
0
        private void delBtn_Click(object sender, RoutedEventArgs e)
        {
            WebDBEntities  db = new WebDBEntities();
            Finished_Goods fg = new Finished_Goods();

            if (isNew)
            {
                fgidBox.Text   = 0000.ToString();
                descBox.Text   = "";
                priceBox.Text  = "$0.00";
                packBox.Text   = "";
                errBox.Content = "";
                return;
            }
            else
            {
                db.Finished_Goods.Remove(db.Finished_Goods.Find(db.Finished_Goods.ToArray().ElementAt(curPos).FGID));
                db.SaveChanges();
                loadData(curPos);
                errBox.Content = "";
            }
        }