public IHttpActionResult PutProduct(tbl_products product)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         tbl_products objPro = new tbl_products();
         objPro = ssEntity.tbl_products.Find(product.pro_id);
         if (objPro != null)
         {
             objPro.pro_name     = product.pro_name;
             objPro.pro_img      = product.pro_img;
             objPro.pro_details  = product.pro_details;
             objPro.pro_price    = product.pro_price;
             objPro.pro_quantity = product.pro_quantity;
         }
         this.ssEntity.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
     return(Ok(product));
 }
Example #2
0
        public string InsertLocal(tbl_products args)
        {
            string result = "";
            List <tbl_products> listProducts = new List <tbl_products>();
            int id = DateTime.Now.ToString().GetHashCode();

            if (Session["products"] != null)
            {
                listProducts = (List <tbl_products>)Session["products"];
            }
            if (ValidateExist(args, listProducts))
            {
                tbl_products product = new tbl_products
                {
                    id_product  = id,
                    number      = args.number,
                    title       = args.title,
                    price       = args.price,
                    last_update = DateTime.Now
                };

                listProducts.Add(product);
                Session["products"] = listProducts;

                InsertProductCategories(product.id_product, args.ids_product_categories);
                result = "Producto guardado exitosamente!";
            }
            else
            {
                result = "El producto ya existe en la base de datos";
            }
            return(result);
        }
Example #3
0
        public string InsertDb(tbl_products args)
        {
            string result = "";

            if (ValidateExist(args, null))
            {
                tbl_products product = new tbl_products
                {
                    number      = args.number,
                    title       = args.title,
                    price       = args.price,
                    last_update = DateTime.Now
                };
                db.tbl_products.Add(product);
                db.SaveChanges();

                InsertProductCategories(product.id_product, args.ids_product_categories);
                result = "Producto guardado exitosamente!";
            }
            else
            {
                result = "El producto ya existe en la base de datos";
            }
            return(result);
        }
Example #4
0
 public ActionResult AddProduct(tbl_products tblprod, HttpPostedFileBase[] pic, string code, int quantity)
 {
     //string pass = RandomPassword(quantity);                       // getting random password
     try
     {
         if (db.tbl_products.Any(p => p.code == code))
         {
             Response.Write("<script>alert('Your code is already exists try another one')</script>");
         }
         else
         {
             tbl_pic tblpic = new tbl_pic();
             //ensure model state is valid
             if (ModelState.IsValid)
             {
                 //iterating through multiple file collection
                 string[] picarray = new string[4];
                 int      i        = 0;
                 foreach (HttpPostedFileBase file in pic)
                 {
                     //Checking file is available to save.
                     if (file != null)
                     {
                         string randomname     = Path.GetRandomFileName();
                         var    InputFileName  = randomname + Path.GetFileName(file.FileName);
                         var    ServerSavePath = Path.Combine(Server.MapPath("~/Content/productimg/") + InputFileName);
                         //Save file to server folder
                         file.SaveAs(ServerSavePath);
                         picarray[i] = InputFileName;
                         i++;
                     }
                 }
                 db.tbl_products.Add(tblprod);
                 db.SaveChanges();
                 tblpic.pic1        = picarray[0];
                 tblpic.pic2        = picarray[1];
                 tblpic.pic3        = picarray[2];
                 tblpic.pic4        = picarray[3];
                 tblpic.subcategory = tblprod.subcategory;
                 tblpic.code        = tblprod.subcategory;
                 db.tbl_pic.Add(tblpic);
                 db.SaveChanges();
                 //assigning file uploaded status to ViewBag for showing message to user.
                 ViewBag.msg = " Items uploaded successfully.";
             }
             else
             {
                 ViewBag.msg = "Please upload only 4 images";
             }
         }
     }
     catch (Exception e)
     {
         ViewBag.msg = "something went wrong please try again later";
     }
     return(View());
 }
Example #5
0
        public ActionResult delstock(int id)
        {
            tbl_products prod = db.tbl_products.SingleOrDefault(p => p.productid == id);

            db.tbl_products.Remove(prod);
            db.SaveChanges();
            Response.Redirect("viewproducts");
            return(View());
        }
Example #6
0
        public ActionResult itemdesc(string name, string size)
        {
            string       desc = "";
            tbl_products lst  = db.tbl_products.SingleOrDefault(m => m.name == name && m.size == size);

            if (lst != null)
            {
                desc = lst.category + "/" + lst.subcategory + "/" + lst.name + "/" + lst.code;
            }
            TempData["itemid"] = lst.productid;
            return(Json(desc, JsonRequestBehavior.AllowGet));
        }
        public IHttpActionResult DeleteProduct(int id)
        {
            tbl_products myPro = ssEntity.tbl_products.Find(id);

            if (myPro == null)
            {
                return(NotFound());
            }
            ssEntity.tbl_products.Remove(myPro);
            ssEntity.SaveChanges();
            return(Ok(myPro));
        }
Example #8
0
        private bool validateToCategory(tbl_products args)
        {
            bool result = true;

            for (int i = 0; i < args.ids_product_categories.Count(); i++)
            {
                if (db.tbl_relationship_pc.Any(pc => pc.id_product == args.id_product &&
                                               pc.id_product_category == args.ids_product_categories[i]))
                {
                    result = false;
                }
            }
            return(result);
        }
Example #9
0
 public ActionResult productin(tbl_in tblin)
 {
     try
     {
         tblin.itemid = Convert.ToInt32(TempData["itemid"].ToString());
         db.tbl_in.Add(tblin);
         db.SaveChanges();
         tbl_products tblprod = db.tbl_products.SingleOrDefault(p => p.productid == tblin.itemid);
         tblprod.quantity += tblin.quantity;
         db.SaveChanges();
         ViewBag.msg = "Operation Successfull";
     }
     catch (Exception e)
     {
         ViewBag.msg = "something went wrong" + e;
     }
     return(View());
 }
 public IHttpActionResult PostEmployee(tbl_products data)
 {
     // ModelSate review for next lesson
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         ssEntity.tbl_products.Add(data);
         ssEntity.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
     return(Ok(data));
 }
        public IHttpActionResult GetProductDetails(int id)
        {
            tbl_products Obj = new tbl_products();

            try
            {
                Obj = ssEntity.tbl_products.Find(id);
                if (Obj == null)
                {
                    return(NotFound());
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(Ok(Obj));
        }
Example #12
0
        public ActionResult checkquantity(float quantity, string name, string size)
        {
            bool         msg   = true;
            float        dbqty = 1;
            tbl_products lst   = db.tbl_products.SingleOrDefault(p => p.name == name && p.size == size);

            if (lst != null)
            {
                if (lst.quantity < quantity)
                {
                    msg = false;
                }
                else
                {
                    msg = true;
                }
                dbqty = (float)lst.quantity;
            }
            return(Json(new { msg, dbqty }, JsonRequestBehavior.AllowGet));
        }
Example #13
0
        public ActionResult loadproduct(int id)
        {
            List <tbl_products> prodmarbles = db.tbl_products.Where(p => p.category == "Marble").ToList();

            ViewData["prodmarbles"] = prodmarbles;
            List <tbl_products> prodtiles = db.tbl_products.Where(p => p.category == "Tiles").ToList();

            ViewData["prodtiles"] = prodtiles;
            List <tbl_products> prodstones = db.tbl_products.Where(p => p.category == "Stones").ToList();

            ViewData["prodstones"] = prodstones;

            tbl_pic prodpic = db.tbl_pic.SingleOrDefault(p => p.picid == id);

            ViewData["prodpic"] = prodpic;
            tbl_products proddetail = db.tbl_products.SingleOrDefault(u => u.productid == id);

            ViewData["proddetail"] = proddetail;
            return(View());
        }
Example #14
0
        //ajax method for adding item
        public ActionResult additem(tbl_out tblout, string itemname, string itemdescription, float quantity, string size, string billno, string date, string partyname, string mobile)
        {
            bool res = false;

            try
            {
                tblout.itemid = Convert.ToInt32(TempData["itemid"].ToString());
                db.tbl_out.Add(tblout);
                db.SaveChanges();
                tbl_products tblprod = db.tbl_products.SingleOrDefault(p => p.productid == tblout.itemid);
                tblprod.quantity -= tblout.quantity;
                db.SaveChanges();
                ViewBag.msg = "Operation successfull.server";
                res         = true;
            }
            catch (Exception e)
            {
                ViewBag.msg = "something went wrong server";
            }
            return(Json(/*new { Result = "Success", Message = "Saved Successfully" }*/ res, JsonRequestBehavior.AllowGet));
        }
Example #15
0
        private bool ValidateExist(tbl_products args, List <tbl_products> listProducts)
        {
            bool result         = true;
            var  sessionStorage = Session["isLocalStorage"];

            if (sessionStorage == null || (bool)sessionStorage == false)
            {
                if (db.tbl_products.Any(p => p.number == args.number || p.title == args.title))
                {
                    result = false;
                }
            }
            else if ((bool)sessionStorage == true)
            {
                if (listProducts.Any(p => p.number == args.number || p.title == args.title))
                {
                    result = false;
                }
            }
            return(result);
        }
Example #16
0
        public string Insert(tbl_products args)
        {
            //  args.price = (decimal)args.price.ToString().Replace(',','');
            string result = "";

            try
            {
                var sessionStorage = Session["isLocalStorage"];
                if (sessionStorage == null || (bool)sessionStorage == false)
                {
                    result = InsertDb(args);
                }
                else if ((bool)sessionStorage == true)
                {
                    result = InsertLocal(args);
                }
                return(result);
            }
            catch (Exception error)
            {
                result = error.Message.ToString();
            }
            return(result);
        }