Ejemplo n.º 1
0
        public int Add(Image file)
        {
            int id = 0;

            if (file.ImageFile != null)
            {
                string fileName  = Path.GetFileNameWithoutExtension(file.ImageFile.FileName);
                string extension = Path.GetExtension(file.ImageFile.FileName);
                fileName       = fileName + DateTime.Now.ToString("tijarat") + extension;
                file.ImagePath = "~/Images/Product/" + fileName;
                fileName       = Path.Combine(Server.MapPath("~/Images/Product/"), fileName);
                file.ImageFile.SaveAs(fileName);
                using (Smart_POS2Image db = new Smart_POS2Image())
                {
                    db.Images.Add(file);
                    db.SaveChanges();
                    id = db.Images.Max(image => image.ImageID);
                }
                ModelState.Clear();
            }
            else
            {
                TempData["AlertMessage"] = "Image Path is Null ";
            }
            // after successfully uploading redirect the user
            return(id);
        }
Ejemplo n.º 2
0
        public string ImageView(int id)
        {
            Image imagefile = new Image();

            using (Smart_POS2Image db = new Smart_POS2Image())
            {
                imagefile = db.Images.Where(image => image.ImageID == id).FirstOrDefault();
            }
            return(imagefile.ImagePath);
        }
Ejemplo n.º 3
0
        public ActionResult AddOrEdit(mvcProductModel product, Image file)
        {
            //int shopId = shop.GetShop();
            //product.ShopId = shopId;
            if (file.ImageFile != null)
            {
                string fileName  = Path.GetFileNameWithoutExtension(file.ImageFile.FileName);
                string extension = Path.GetExtension(file.ImageFile.FileName);
                fileName       = fileName + DateTime.Now.ToString("tijarat") + extension;
                file.ImagePath = "/Images/Product/" + fileName;
                fileName       = Path.Combine(Server.MapPath("~/Images/Product/"), fileName);
                file.ImageFile.SaveAs(fileName);
                using (Smart_POS2Image db = new Smart_POS2Image())
                {
                    db.Images.Add(file);
                    db.SaveChanges();
                    product.ImageID = db.Images.Max(image => image.ImageID);
                }
                ModelState.Clear();
            }
            else
            {
                TempData["AlertMessage"] = "Image Path is Null ";
            }



            if (product.ProdId == 0)
            {
                HttpResponseMessage request = GlobalHttp.WebApiClient.PostAsJsonAsync("Products", product).Result;
                TempData["SuccessMessage"] = product.ProdName + " Record  Added Succfully!!";
            }
            else
            {
                HttpResponseMessage response = GlobalHttp.WebApiClient.PutAsJsonAsync("Products/" + product.ProdId, product).Result;
                TempData["SuccessMessage"] = product.ProdName + " Record Updated Succfully!!";
            }

            return(RedirectToAction("Index"));
        }