Ejemplo n.º 1
0
        public JsonResult byVariant(string vr)
        {
            if (vr != null || vr != "null")
            {
                List <int> s = JsonConvert.DeserializeObject <List <int> >(vr);

                //list
                var product = new List <product_tbl>();
                foreach (var v in s)
                {
                    //get varint type data

                    var p = db.product_variant_value.Where(a => a.variant_unit_id == v).GroupBy(a => a.product_id).Select(g => new { product_id = g.Key }).ToList();
                    //var p = db.product_variant_value.Where(a => a.variant_unit_id == v).ToList();
                    foreach (var o in p)
                    {
                        //var k = IGrouping<int>g => new { p_name = g.Key }
                        //get product
                        var p1 = db.product_tbl.Find(o.product_id);
                        var ps = new product_tbl();
                        ps.product_id = p1.product_id;
                        ps.p_name     = p1.p_name;
                        ps.price      = p1.price;
                        ps.points     = p1.points;
                        ps.quantity   = p1.quantity;
                        ps.main_image = p1.main_image;
                        product.Add(ps);
                    }
                }

                return(Json(new { list = product }, JsonRequestBehavior.AllowGet));
            }
            return(Json(JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public IHttpActionResult Postproduct_tbl(product_tbl product_tbl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.product_tbl.Add(product_tbl);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (product_tblExists(product_tbl.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = product_tbl.Id }, product_tbl));
        }
Ejemplo n.º 3
0
        public IHttpActionResult Putproduct_tbl(int id, product_tbl product_tbl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product_tbl.Id)
            {
                return(BadRequest());
            }

            db.Entry(product_tbl).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!product_tblExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public IHttpActionResult Getproduct_tbl(int id)
        {
            product_tbl product_tbl = db.product_tbl.Find(id);

            if (product_tbl == null)
            {
                return(NotFound());
            }

            return(Ok(product_tbl));
        }
Ejemplo n.º 5
0
        public IHttpActionResult Deleteproduct_tbl(int id)
        {
            product_tbl product_tbl = db.product_tbl.Find(id);

            if (product_tbl == null)
            {
                return(NotFound());
            }

            db.product_tbl.Remove(product_tbl);
            db.SaveChanges();

            return(Ok(product_tbl));
        }
        public ActionResult Add(MvcProductModel product)
        {
            if (ModelState.IsValid)
            {
                product_tbl obj = new product_tbl();
                obj.Id       = product.Id;
                obj.Name     = product.Name;
                obj.Category = product.Category;
                obj.Price    = product.Price;

                string fileName      = Path.GetFileNameWithoutExtension(product.ImageFile.FileName);
                string fileExtension = Path.GetExtension(product.ImageFile.FileName);
                fileName           = fileName + DateTime.Now.ToString("yymmssfff") + fileExtension;
                product.smallImage = "~/SImages/" + fileName;
                fileName           = Path.Combine(Server.MapPath("~/SImages/"), fileName);
                product.ImageFile.SaveAs(fileName);

                string fileName1      = Path.GetFileNameWithoutExtension(product.ImageFile1.FileName);
                string fileExtension1 = Path.GetExtension(product.ImageFile1.FileName);
                fileName1         = fileName1 + DateTime.Now.ToString("yymmssfff") + fileExtension1;
                product.longImage = "~/LImages/" + fileName1;
                fileName1         = Path.Combine(Server.MapPath("~/LImages/"), fileName1);
                product.ImageFile1.SaveAs(fileName1);

                obj.smallImage       = product.smallImage;
                obj.longImage        = product.longImage;
                obj.shortDescription = product.shortDescription;
                obj.longDescription  = product.longDescription;
                obj.Quantity         = product.Quantity;

                if (product.Id == 0)
                {
                    HttpResponseMessage responses = MvcGlobalVariables.webapiclient.PostAsJsonAsync("product", obj).Result;
                    TempData["success"] = product.Name.ToString() + " Added Successfully.";
                }
                else
                {
                    HttpResponseMessage responses = MvcGlobalVariables.webapiclient.PutAsJsonAsync("product/" + product.Id, obj).Result;
                    TempData["success"] = product.Name.ToString() + " Updated Successfully";
                }

                return(RedirectToAction("ProductList"));
            }

            return(View());
        }
Ejemplo n.º 7
0
        public JsonResult filterProduct(int max, int min, string pvv, int cid)
        {
            if (pvv != "")
            {
                List <int> s = JsonConvert.DeserializeObject <List <int> >(pvv);

                //list
                var product = new List <product_tbl>();
                foreach (var v in s)
                {
                    //get varint type data

                    var pro = db.product_variant_value.Where(a => a.variant_unit_id == v).GroupBy(a => a.product_id).Select(g => new { product_id = g.Key }).ToList();
                    //var p = db.product_variant_value.Where(a => a.variant_unit_id == v).ToList();
                    foreach (var o in pro)
                    {
                        //var k = IGrouping<int>g => new { p_name = g.Key }
                        //get product
                        var p1 = db.product_tbl.Find(o.product_id);
                        var ps = new product_tbl();
                        ps.product_id = p1.product_id;
                        ps.p_name     = p1.p_name;
                        ps.price      = p1.price;
                        ps.points     = p1.points;
                        ps.quantity   = p1.quantity;
                        ps.main_image = p1.main_image;
                        product.Add(ps);
                    }
                }

                var p = product.Where(a => a.price >= min && a.price <= max).ToList();

                return(Json(new { list = p }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var p = db.prcFilter(max, min, cid).ToList();

                return(Json(new { list = p }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 8
0
        // GET: product
        public ActionResult detail(int?id)
        {
            var cates   = new List <category_tbl>();
            var Product = new product();

            if (id != null)
            {
                var pro = new List <product_tbl>();
                var p   = db.product_tbl.Find(id);
                var g   = db.product_image_tbl.Where(a => a.product_id == p.product_id).ToList();

                Product.discription      = p.discription;
                Product.main_image       = p.main_image;
                Product.meta_description = p.meta_description;
                Product.meta_keyword     = p.meta_keyword;
                Product.meta_title       = p.meta_title;
                Product.price            = p.price;
                Product.product_id       = p.product_id;
                Product.quantity         = p.quantity;
                Product.videoLink        = p.VideoLink;

                //get discount price
                var date = DateTime.Today;
                var d    = db.product_discount_tbl.OrderBy(a => a.priority).Where(a => a.date_start <= date && a.date_end >= date && a.quantity != 0 && a.product_id == id).FirstOrDefault();
                if (d != null)
                {
                    Product.discountPrice = Convert.ToDecimal(Product.price - d.price);
                }

                Product.p_name  = p.p_name;
                ViewBag.imgPath = ConfigurationManager.AppSettings["productimgPath"].ToString();
                ViewBag.Variant = cc.variant(p.product_id);
                //add gallery img
                Product.gallery = g;

                var r = db.product_related_tbl.Where(a => a.product_ID == p.product_id).ToList();
                foreach (var rel in r)
                {
                    var pr = db.product_tbl.OrderByDescending(a => a.product_id).Where(a => a.product_id == rel.releted_product_ID).ToList();
                    foreach (var p1 in pr)
                    {
                        var ps = new product_tbl();
                        ps.product_id = p1.product_id;
                        ps.p_name     = p1.p_name;
                        ps.price      = p1.price;
                        ps.points     = p1.points;
                        ps.quantity   = p1.quantity;
                        ps.main_image = p1.main_image;
                        pro.Add(ps);
                    }
                }
                //this section ic common
                var    home      = new HomeController();
                string sessionID = Session.SessionID.ToString();
                ViewBag.showMenu       = home.menu();
                ViewBag.footer         = home.footerSocial();
                ViewBag.cartPanal      = home.cartPanl(sessionID);
                ViewBag.simpalCart     = home.simpalCart(sessionID);
                Product.relatedProduct = pro;
                ViewBag.bycategory     = bycategory(id);
                return(View(Product));
            }
            else
            {
                return(HttpNotFound());
            }
        }