Beispiel #1
0
        public ActionResult Edit(EditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Get the About entity if it exists, so ImageUrl doesn't get overriden to null if no image is selected and user is saving in json instead of sql.
            var about = Services.About.Exists(model.Title) ? Services.About.GetByTitle(model.Title) : new About();

            about.Name    = model.Name;
            about.Title   = model.Title;
            about.Content = model.Content;
            // Save the image in blob storage
            if (model.Image != null)
            {
                var image    = new NBlog.Web.Application.Service.Entity.Image();
                var fileName = Path.GetFileName(model.Image.FileName);
                // Scale the image before saving
                using (var scaledImageStream = new MemoryStream())
                {
                    var settings = new ResizeSettings(200, 150, FitMode.None, "jpg");
                    ImageBuilder.Current.Build(model.Image.InputStream, scaledImageStream, settings);
                    image.StreamToUpload = scaledImageStream;
                    // Set FileName to save as, gets read as a repository key
                    image.FileName = fileName;
                    Services.Image.Save(image);
                }
                // Get the url to link to the About Entity
                about.ImageUrl = Services.Image.GetByFileName(fileName).Uri;
            }
            Services.About.Save(about);

            return(RedirectToAction("Index", "About"));
        }
Beispiel #2
0
		public ActionResult Edit(EditModel model)
		{
			if (!ModelState.IsValid)
			{
				return View(model);
			}

			// Get the About entity if it exists, so ImageUrl doesn't get overriden to null if no image is selected and user is saving in json instead of sql.
			var about = Services.About.Exists(model.Title) ? Services.About.GetByTitle(model.Title) : new About();
			about.Name = model.Name;
			about.Title = model.Title;
			about.Content = model.Content;
			// Save the image in blob storage
			if (model.Image != null)
			{
				var image = new NBlog.Web.Application.Service.Entity.Image();
				var fileName = Path.GetFileName(model.Image.FileName);
				// Scale the image before saving
				using (var scaledImageStream = new MemoryStream())
				{
					var settings = new ResizeSettings(200, 150, FitMode.None, "jpg");
					ImageBuilder.Current.Build(model.Image.InputStream, scaledImageStream, settings);
					image.StreamToUpload = scaledImageStream;
					// Set FileName to save as, gets read as a repository key
					image.FileName = fileName;
					Services.Image.Save(image);
				}
				// Get the url to link to the About Entity
				about.ImageUrl = Services.Image.GetByFileName(fileName).Uri;
			}
			Services.About.Save(about);

			return RedirectToAction("Index", "About");
		}
Beispiel #3
0
		public void Save(Image stream)
		{
			_repository.Save<Image>(stream);
		}