public ActionResult SaveData(HttpPostedFileBase file, PageContent pageContent) { PageContent pContent = db.PageContents.SingleOrDefault(); if (pContent == null) pContent = new PageContent(); if (file != null) { var fileName = Path.GetFileName(file.FileName); string path = Server.MapPath("/Uploads/logo/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filePath = System.IO.Path.Combine(path, fileName); file.SaveAs(filePath); string fl = filePath.Substring(path.LastIndexOf("\\")); string[] split = fl.Split('\\'); string newpath = split[1]; string imagepath = "/uploads/logo/" + newpath; pContent.Logo = imagepath; } if (!string.IsNullOrWhiteSpace(pageContent.Contact1)) { pContent.Contact1 = pageContent.Contact1; } if (!string.IsNullOrWhiteSpace(pageContent.Contact2)) { pContent.Contact2 = pageContent.Contact2; } if (!string.IsNullOrWhiteSpace(pageContent.Facebook)) { pContent.Facebook = pageContent.Facebook; } if (!string.IsNullOrWhiteSpace(pageContent.Twitter)) { pContent.Twitter = pageContent.Twitter; } if (!string.IsNullOrWhiteSpace(pageContent.GooglePlus)) { pContent.GooglePlus = pageContent.GooglePlus; } if (!string.IsNullOrWhiteSpace(pageContent.Email)) { pContent.Email = pageContent.Email; } if (pContent.PageContentId == 0) db.PageContents.Add(pContent); db.SaveChanges(); return RedirectToAction("StaticContent"); }
public ActionResult StaticContent() { PageContent pageContent = db.PageContents.SingleOrDefault(); if (pageContent == null) pageContent = new PageContent(); return View(pageContent); }