protected void Page_Load(object sender, EventArgs e) { using (DataStorage context = new DataStorage()) { string imageName = Request.Files["image"].FileName; if (!string.IsNullOrEmpty(imageName)) { imageName = Path.GetFileName(imageName); string imagePath = Server.MapPath("~/Content/Objects/" + imageName); Request.Files["image"].SaveAs(imagePath); Request.Files["image"].InputStream.Close(); ImageContent imageItem = new ImageContent(); imageItem.FileName = imageName; imageItem.Language = SystemSettings.CurrentLanguage; imageItem.Url = Request.Form["url"]; context.AddToImageContent(imageItem); context.SaveChanges(); } //List<ImageContent> images = context.ImageContent.Where(i => i.Language == SystemSettings.CurrentLanguage).Select(i => i).ToList(); //return View(images); } Response.Write("<script>window.close()</script>"); //Response.Redirect("Admin/EditPicture/?contentUrl=" + contentUrl + "&controllerName=" + controllerName); }
public static void SetText(string contentUrl, string text, string title, string keywords, string description) { using (DataStorage context = new DataStorage()) { SiteContent content = context.SiteContent.Where(sc => sc.Url == contentUrl).Select(sc => sc).First(); content.Text = text; content.Title = title; content.Keywords = keywords; content.Description = description; context.SaveChanges(); } }
private static void UpdateApplicationData(string name, string value) { HttpRuntime.Cache.Remove("ApplicationData_" + name); using (DataStorage context = new DataStorage()) { var data = (from appData in context.ApplicationSettings where appData.Name == name select appData).First(); data.Value = value; context.SaveChanges(); } }
public ActionResult EditPicture(FormCollection form) { using (DataStorage context = new DataStorage()) { string imageName = Request.Files["image"].FileName; if (!string.IsNullOrEmpty(imageName)) { imageName = Path.GetFileName(imageName); string imagePath = Server.MapPath("~/Content/Objects/" + imageName); Request.Files["image"].SaveAs(imagePath); Request.Files["image"].InputStream.Close(); ImageContent imageItem = new ImageContent(); imageItem.FileName = imageName; imageItem.Language = SystemSettings.CurrentLanguage; imageItem.Url = form["url"]; context.AddToImageContent(imageItem); context.SaveChanges(); } List<ImageContent> images = context.ImageContent.Where(i => i.Language == SystemSettings.CurrentLanguage).Select(i => i).ToList(); return View(images); } }
public ActionResult DeleteSubMenuItem(int id, string redirectUrl) { using (DataStorage context = new DataStorage()) { SiteContent content = (from c in context.SiteContent where c.Id == id select c).First(); context.DeleteObject(content); context.SaveChanges(); return Redirect(redirectUrl); } }
public ActionResult AddSubMenuItem(FormCollection form, string redirectUrl, string tName, string tTitle) { if (!string.IsNullOrEmpty(tName) && !string.IsNullOrEmpty(tTitle)) { using (DataStorage context = new DataStorage()) { SiteContent parent = (from c in context.SiteContent.Include("Parent") where c.Language == SystemSettings.CurrentLanguage && c.Name == "Services" select c).First(); SiteContent content = new SiteContent(); content.Name = tName; content.Title = tTitle; content.Language = SystemSettings.CurrentLanguage; content.Url = tTitle; content.SortOrder = 4; content.Parent = parent; context.AddToSiteContent(content); context.SaveChanges(); } } return Redirect(redirectUrl); }
public ActionResult UpdateButtonsState(FormCollection form, string redirectUrl) { using (DataStorage context = new DataStorage()) { if (!string.IsNullOrEmpty(form["enablities"])) { JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary<string, string> enables = serializer.Deserialize<Dictionary<string, string>>(form["enablities"]); foreach (string key in enables.Keys) { int id = int.Parse(key); ButtonStatuses sButton = (from button in context.ButtonStatuses where button.Id == id select button).First(); sButton.SwitchedOn = bool.Parse(enables[key]); } context.SaveChanges(); } List<ButtonStatuses> buttons = (from button in context.ButtonStatuses where button.Language == SystemSettings.CurrentLanguage orderby button.SortOrder ascending select button).ToList(); return Redirect(redirectUrl); } }
public ActionResult DeletePicture(int id, string contentUrl, string controllerName) { using (DataStorage context = new DataStorage()) { ImageContent image = (from i in context.ImageContent where i.Id == id select i).First(); string imageName = image.FileName; context.DeleteObject(image); context.SaveChanges(); string path = Server.MapPath("~/Content/Objects/" + imageName); if (!string.IsNullOrEmpty(imageName)) { //DeleteFileInTheThread(path); System.IO.File.Delete(path); } } return RedirectToAction("EditPicture", "Admin", new { contentUrl = contentUrl }); }