public ActionResult Edit([Bind(Exclude = "Image")] BlogHeader blogHeader, HttpPostedFileBase Image) { if (ModelState.IsValid) { if (Image != null) { if (Extensions.Extensions.CheckImageType(Image) && Extensions.Extensions.CheckImageSize(Image, 10)) { blogHeader.Image = Extensions.Extensions.SaveImage(Server.MapPath("~/Public/images"), Image); db.Entry(blogHeader).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "BlogHeader")); } else { ModelState.AddModelError("Image", "The type of image is incorrect or the size of image is greater than 10 Mb."); } } else { ModelState.AddModelError("Image", "Please choose an image"); } } return(View()); }
public ActionResult Edit(int?id) { if (id == null) { return(HttpNotFound("ID is missing")); } BlogHeader blogHeader = db.BlogHeaders.Find(id); if (blogHeader == null) { return(HttpNotFound("ID was not found")); } return(View(blogHeader)); }
public void Deserialize_Provides_AdditionalData() { // Arrange // What property are we going to add / check is put in the right place? KeyValuePair <String, JToken> propertyToCheck = new KeyValuePair <String, JToken> ( "AddedProperty", JToken.FromObject("Added Value") ); // Set up the dictionary of properties we expect to see IDictionary <String, JToken> expectedAdditionalData = new Dictionary <String, JToken>() { { propertyToCheck.Key, propertyToCheck.Value } }; // Generate the new blog to use to save blog items IBlog blog = new Blog( new BlogParameters() { Id = "TestBlogId", Provider = new BlogMemoryProvider() }); IBlogItem blogItem = blog.Save(new BlogItem() { }); // Save the blog item to make sure it is safe String output = JsonConvert.SerializeObject(blogItem, Formatting.Indented); // Serialize it JObject jsonObject = JObject.Parse(output); // Parse the output back as a generic JObject JObject header = (JObject)jsonObject["Header"]; // Get the header section to work with // Act header.Property("State") .AddAfterSelf(new JProperty(propertyToCheck.Key, propertyToCheck.Value)); // Add the new property in BlogHeader deserializedItem = JsonConvert.DeserializeObject <BlogHeader>(header.ToString()); // Deserialize // Assert Assert.Equal(expectedAdditionalData, deserializedItem.AdditionalData); // Are the dictionaries equal to what we expect? }