public ActionResult Index(IEnumerable <HttpPostedFileBase> files)
        {
            var        id         = Convert.ToInt32(Request.Cookies["id"].Value);
            Restaraunt Restaraunt = restRepository.GetRestarauntByID(id);
            var        res        = new List <HttpPostedFileBase>();
            // set path and foldername
            string FolderName = "Restaraunt" + id;
            string Folder     = Server.MapPath("~/Content/Images/RestaurantImages/");
            string pathString = System.IO.Path.Combine(Folder, FolderName);

            System.IO.Directory.CreateDirectory(pathString);
            string ForSaving = Server.MapPath("~/Content/Images/RestaurantImages/" + FolderName + "/");
            //
            int counter = 0;

            foreach (var file in files)
            {
                System.Drawing.Image imageObject = new Bitmap(file.InputStream);

                string FileName          = counter + ".jpg";
                string ThumbnailFileName = "small_" + counter + ".jpg";

                string Url          = System.IO.Path.Combine(ForSaving, FileName);
                string ThumbnailUrl = System.IO.Path.Combine(ForSaving, ThumbnailFileName);
                counter++;

                imageObject.Save(Url, System.Drawing.Imaging.ImageFormat.Jpeg);
                GetThumbnail(imageObject, 200, 200).Save(ThumbnailUrl, System.Drawing.Imaging.ImageFormat.Jpeg);

                // adding url to DB
                // костыль. не универсальный способ для сохранения URL
                Url = System.IO.Path.Combine("http://rest-rate.azurewebsites.net/Content/Images/RestaurantImages/" + FolderName + "/", FileName);
                //
                Domain.Entities.Image New = new Domain.Entities.Image()
                {
                    Url = Url, Name = FileName
                };
                New.RestarauntID = id;
                imageRepository.SaveImage(New);
                //
            }
            return(null);
        }
Пример #2
0
        public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
        {
            var id = Convert.ToInt32(Request.Cookies["id"].Value);
            Restaraunt Restaraunt = restRepository.GetRestarauntByID(id);
            var res = new List<HttpPostedFileBase>();
            // set path and foldername
            string FolderName = "Restaraunt" + id;
            string Folder = Server.MapPath("~/Content/Images/RestaurantImages/");
            string pathString = System.IO.Path.Combine(Folder, FolderName);
            System.IO.Directory.CreateDirectory(pathString);
            string ForSaving = Server.MapPath("~/Content/Images/RestaurantImages/" + FolderName + "/");
            //
            int counter = 0;
            foreach (var file in files)
            {
                System.Drawing.Image imageObject = new Bitmap(file.InputStream);

                string FileName = counter + ".jpg";
                string ThumbnailFileName = "small_" + counter + ".jpg";

                string Url = System.IO.Path.Combine(ForSaving, FileName);
                string ThumbnailUrl = System.IO.Path.Combine(ForSaving, ThumbnailFileName);
                counter++;

                imageObject.Save(Url, System.Drawing.Imaging.ImageFormat.Jpeg);
                GetThumbnail(imageObject, 200, 200).Save(ThumbnailUrl, System.Drawing.Imaging.ImageFormat.Jpeg);

                // adding url to DB
                // костыль. не универсальный способ для сохранения URL
                Url = System.IO.Path.Combine("http://rest-rate.azurewebsites.net/Content/Images/RestaurantImages/" + FolderName + "/", FileName);
                //
                Domain.Entities.Image New = new Domain.Entities.Image() { Url = Url, Name = FileName };
                New.RestarauntID = id;
                imageRepository.SaveImage(New);
                //

            }
            return null;
        }