public ActionResult Manage(string siteName) { using (AnonoMightEntities anonoMightEntities = new AnonoMightEntities()) { Site site = anonoMightEntities.Sites.SingleOrDefault(o => o.SiteName == siteName); ManageSiteModel manageSiteModel = new ManageSiteModel(site); manageSiteModel.Name = siteName; ViewBag.Message = string.Empty; return View(manageSiteModel); } }
public ActionResult Manage(HttpPostedFileBase imageFile, ManageSiteModel manageSiteModel) { if (ModelState.IsValid) { if (imageFile != null) { byte[] logo = new byte[imageFile.ContentLength]; imageFile.InputStream.Read(logo, 0, imageFile.ContentLength); using (AnonoMightEntities anonoMightEntities = new AnonoMightEntities()) { Site site = anonoMightEntities.Sites.SingleOrDefault(o => o.SiteName == manageSiteModel.Name); if (site == null) { site = new Site(); anonoMightEntities.Sites.Add(site); site.SiteName = manageSiteModel.Name; if (manageSiteModel.SiteType == SiteType.Definitions) anonoMightEntities.CreateDefinitionsTable(site.SiteName); else if (manageSiteModel.SiteType == SiteType.FacebookProfiles) anonoMightEntities.CreateFacebookProfilesTable(site.SiteName); else if (manageSiteModel.SiteType == SiteType.ImagePosts) anonoMightEntities.CreateImagePostsTable(site.SiteName); else if (manageSiteModel.SiteType == SiteType.Tweets) anonoMightEntities.CreateTweetsTable(site.SiteName); } site.SiteLogo = logo; site.SiteTitle = manageSiteModel.Title; site.SiteType = (byte)manageSiteModel.SiteType; site.Active = manageSiteModel.Active; site.Description = manageSiteModel.Description; anonoMightEntities.SaveChanges(); } ViewBag.Message = "Site has been saved!"; } else { ViewBag.Message = "No Image Selected!"; } } return View(manageSiteModel); }