Пример #1
0
        public ActionResult DeleteImage(int imageId)
        {
            CustomJsonResult result = new CustomJsonResult();

            try
            {
                RestaurantImages restaurnatImages = db.RestaurantImages.Find(imageId);
                if (restaurnatImages != null)
                {
                    db.RestaurantImages.Remove(restaurnatImages);
                    db.SaveChanges();
                    result.Data = true;
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public ActionResult UploadImages(int restaurantId)
        {
            CustomJsonResult result = new CustomJsonResult();

            try
            {
                string fileName = string.Empty;
                string filePath = string.Empty;
                //string fileExtension = string.Empty;

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    RestaurantImages restaurnatImages = new RestaurantImages();

                    restaurnatImages.ImageName      = Path.GetFileName(Request.Files[i].FileName);
                    restaurnatImages.ImageUrl       = Path.GetFullPath(Request.Files[i].FileName);
                    restaurnatImages.ImageExtension = Path.GetExtension(Request.Files[i].FileName);

                    restaurnatImages.RestaurantId = restaurantId;

                    BinaryReader br    = new BinaryReader(Request.Files[i].InputStream);
                    byte[]       bytes = br.ReadBytes((int)Request.Files[i].InputStream.Length);

                    //Convert the Byte Array to Base64 Encoded string.
                    restaurnatImages.ImageBase64 = Convert.ToBase64String(bytes, 0, bytes.Length);

                    db.RestaurantImages.Add(restaurnatImages);
                    db.SaveChanges();
                }
                result.Data = true;
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }