public ActionResult Index(string answer, int id) { string _answer = HttpUtility.UrlDecode(answer, System.Text.Encoding.Default); CustomMembershipDB db = new CustomMembershipDB(); var question = db.FAQ.SingleOrDefault(q => q.ID == id); if (question != null) { question.Answer = _answer; if (question.NotifyByEmail && !String.IsNullOrEmpty(question.NotifyEmail)) { var msgTitle = "dirot.somee.com. You got the answer on your question."; var msgBody = "Hello. You got the answer to the question that you asked in www.dirot.somee.com." + " Please follow the <a href='www.dirot.somee.com/FAQ' target='_blank'>link</a> to see the answer."; UserRepository.SendEmailThroughGmail(msgTitle, msgBody, question.NotifyEmail); question.NotifyByEmail = false; } db.SaveChanges(); } else { //add error } //return Json(answer, "text/html"); return(Content(_answer, "text/html")); }
public PartialViewResult Edit(FormCollection formCollection) { var userID = int.Parse(formCollection["item.UserId"]); var db = new CustomMembershipDB(); var user = db.Users.SingleOrDefault(u => u.UserId == userID); if(user != null) { user.UserName = String.IsNullOrEmpty(formCollection["item.UserName"]) ? user.UserName : formCollection["item.UserName"]; user.Email = String.IsNullOrEmpty(formCollection["item.Email"]) ? user.Email : formCollection["item.Email"]; DateTime createdDate = user.CreatedDate; if (DateTime.TryParseExact(formCollection["item.CreatedDate"], "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out createdDate)) user.CreatedDate = createdDate; user.IsActivated = String.IsNullOrEmpty(formCollection["item.IsActivated"]) ? user.IsActivated : formCollection["item.IsActivated"].Any(act => act == 't'); user.IsLockedOut = String.IsNullOrEmpty(formCollection["item.IsLockedOut"]) ? user.IsLockedOut : formCollection["item.IsLockedOut"].Any(loc => loc == 't'); user.LastLockedOutReason = formCollection["item.LastLockedOutReason"] == null ? user.LastLockedOutReason : formCollection["item.LastLockedOutReason"]; DateTime lastLockedOutDate = user.LastLockedOutDate; if (DateTime.TryParseExact(formCollection["item.LastLockedOutDate"], "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out lastLockedOutDate)) user.LastLockedOutDate = lastLockedOutDate; if (!formCollection["item.RoleName"].Equals("0") && !user.Roles.Any(r => r.RoleName == formCollection["item.RoleName"])) { var RoleService = new AccountRoleService(); RoleService.AddUsersToRoles(new string[] { user.UserName }, new string[] { formCollection["item.RoleName"] }); } db.SaveChanges(); } return PartialView("_UserPartial", ModelsHelper.GetUserFromTable(user)); // return PartialView("_UserPartial", new TaskTimer.Areas.Admin.Models.User()); }
public ActionResult PagesAddNew(MmgtaaboraPages newPage) { if (ModelState.IsValid) { var db = new CustomMembershipDB(); var newSavedPage = db.MmgtaaboraPages.Add(newPage); db.SaveChanges(); return(RedirectToAction("PagesEdit", new { id = newSavedPage.Id })); } return(View()); }
public ActionResult SitePagesDelete(int id) { var db = new CustomMembershipDB(); var deletePage = db.SiteMainPages.FirstOrDefault(p => p.Id == id); if (deletePage != null) { db.SiteMainPages.Remove(deletePage); db.SaveChanges(); } return(RedirectToAction("SitePages")); }
public ActionResult Delete(int id) { CustomMembershipDB db = new CustomMembershipDB(); var question = db.FAQ.SingleOrDefault(q => q.ID == id); if (question != null) { question.Active = false; db.SaveChanges(); } return(Content("")); }
public ActionResult EfarganPagesSaveSlider(EfarganPages curPage, int id) { if (ModelState.IsValid) { var db = new CustomMembershipDB(); var curPage2 = db.EfarganPages.SingleOrDefault(ef => ef.Id == id); if (curPage2 == null) { //db.EfarganPages.Add(curPage); return(RedirectToAction("EfarganPages")); } else { foreach (var slider in curPage.EfarganPagesSliders) { var sliderToUpdate = curPage2.EfarganPagesSliders.FirstOrDefault(sl => sl.Id == slider.Id); if (sliderToUpdate != null) { sliderToUpdate.SliderTitle = slider.SliderTitle; sliderToUpdate.SliderText = slider.SliderText; sliderToUpdate.SliderLinkText = slider.SliderLinkText; sliderToUpdate.SliderLinkURL = slider.SliderLinkURL; sliderToUpdate.SliderImageFileName = slider.SliderImageFileName; } else if (slider.Id == -1 && ( !string.IsNullOrEmpty(slider.SliderTitle) || !string.IsNullOrEmpty(slider.SliderText) || !string.IsNullOrEmpty(slider.SliderLinkText) || !string.IsNullOrEmpty(slider.SliderLinkURL) || !string.IsNullOrEmpty(slider.SliderImageFileName) )) //add new slider to list { curPage2.EfarganPagesSliders.Add(slider); } } } db.Entry(curPage2).State = EntityState.Modified; db.SaveChanges(); ModelState.Clear(); return(View(curPage2)); } //var qwer1 = Request.Form["EfarganPagesSliders[0].SliderText"].ToString(); return(RedirectToAction("EfarganPages")); }
public ActionResult DeletePermanently(int id) { CustomMembershipDB db = new CustomMembershipDB(); var question = db.FAQ.SingleOrDefault(q => q.ID == id); if (question != null) { var images = question.Images.ToList(); for (int i = 0; i < images.Count; i++) { Helper.RemoveFile(dirName, images[i].Name); // remove image from server db.Images.Remove(images[i]); // remove image from db } db.FAQ.Remove(question); db.SaveChanges(); } return(Content("")); }
public JsonResult Update(User data) { db.Configuration.ProxyCreationEnabled = false; bool success = false; string message = "no record found"; if (data != null && data.UserId > 0) { { var rec = db.Users.Where(a => a.UserId == data.UserId). FirstOrDefault(); //добавление данных в аккаунт rec.Code = data.Code; rec.Discount = data.Discount; rec.FirstName = data.FirstName; rec.LastName = data.LastName; rec.Phone = data.Phone; rec.Email = data.Email; rec.Country = data.Country; rec.State = data.State; rec.City = data.City; rec.PostalCode = data.PostalCode; rec.Address = data.Address; UpdateModel(data); db.SaveChanges(); success = true; message = "Update method called successfully"; } } return(Json(new { data, success, message })); }
void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started Session["start"] = DateTime.Now; Application.Lock(); Application["onlinevisitors"] = Convert.ToInt32(Application["onlinevisitors"]) + 1; Application.UnLock(); // get total visits var appID = Guid.Parse(ConfigurationManager.AppSettings["ApplicationId"]); using (var db = new CustomMembershipDB()) { var curApp = db.Applications.FirstOrDefault(app => app.ApplicationId == appID); if (curApp != null) { curApp.UserCounter++; db.SaveChanges(); Application["totalvisitors"] = curApp.UserCounter; Application["totalusers"] = db.Users.Count(); } } }
public ActionResult SitePagesAddNew(SiteMainPages newPage) { //upload files var saveToDirectory = AppDomain.CurrentDomain.BaseDirectory + "Images\\Site Pages\\"; foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) { continue; } var saveFileName = Path.GetFileName(hpf.FileName); saveFileName = AdminHelper.GetUniqueFileName(saveToDirectory, saveFileName); string savedFileName = Path.Combine( saveToDirectory, saveFileName); hpf.SaveAs(savedFileName); if (file.Equals("TitleImage")) { newPage.TitleImage = saveFileName; } else if (file.Equals("BodyImage")) { newPage.BodyImage = saveFileName; } else if (file.Equals("FooterImage")) { newPage.FooterImage = saveFileName; } } var db = new CustomMembershipDB(); db.SiteMainPages.Add(newPage); db.SaveChanges(); return(RedirectToAction("SitePages")); }
public ActionResult EfarganPagesEdit(EfarganPages curPage, int id) { if (ModelState.IsValid) { var db = new CustomMembershipDB(); var curPage2 = db.EfarganPages.SingleOrDefault(ef => ef.Id == id); if (curPage2 == null) { //db.EfarganPages.Add(curPage); return(RedirectToAction("EfarganPages")); } else { //update page data if (curPage.EfarganPagesParagraphs.Count == 0 && curPage.EfarganPagesSliders.Count == 0 && curPage.EfarganPagesTickers.Count == 0) { curPage2.TitleTag = curPage.TitleTag; curPage2.MetaTag = curPage.MetaTag; curPage2.DescriptionTag = curPage.DescriptionTag; curPage2.MenuText = curPage.MenuText; curPage2.TicketTitle = curPage.TicketTitle; curPage2.TicketLinkText = curPage.TicketLinkText; curPage2.TicketLinkURL = curPage.TicketLinkURL; } //update / add to sliders if (curPage.EfarganPagesSliders.Count > 0) { foreach (var slider in curPage.EfarganPagesSliders) { //get file data var file = Request.Files["SliderImage_" + slider.Id]; var savedFileName = ""; if (file != null && file.ContentLength > 0) //need to save a new file { //delete old file if file already exist if (slider.SliderImageURL != null && !string.IsNullOrEmpty(slider.SliderImageURL) && slider.SliderImageFileName != null && !string.IsNullOrEmpty(slider.SliderImageFileName)) { var oldFileName = slider.SliderImageURL.Split('/').Last(); var savedToDirectory = AppDomain.CurrentDomain.BaseDirectory + AdminEfarganHelper.PageImagesPath; var savedOldFilePath = savedToDirectory + "/" + oldFileName; System.IO.File.Delete(savedOldFilePath); } savedFileName = AdminEfarganHelper.SavePageImage(file); } //add / update slider data var sliderToUpdate = curPage2.EfarganPagesSliders.FirstOrDefault(sl => sl.Id == slider.Id); if (sliderToUpdate != null) { sliderToUpdate.SliderTitle = slider.SliderTitle; sliderToUpdate.SliderText = slider.SliderText; sliderToUpdate.SliderLinkText = slider.SliderLinkText; sliderToUpdate.SliderLinkURL = slider.SliderLinkURL; if (file != null && file.ContentLength > 0) //need to save a new file { sliderToUpdate.SliderImageURL = AdminEfarganHelper.PageImagesPath + savedFileName.Split('/').Last(); sliderToUpdate.SliderImageFileName = file.FileName; } } else if (slider.Id == -1 && ( !string.IsNullOrEmpty(slider.SliderTitle) || !string.IsNullOrEmpty(slider.SliderText) || !string.IsNullOrEmpty(slider.SliderLinkText) || !string.IsNullOrEmpty(slider.SliderLinkURL) || !string.IsNullOrEmpty(slider.SliderImageFileName) )) //add new slider to list { if (file != null && file.ContentLength > 0) //need to save a new file { slider.SliderImageURL = AdminEfarganHelper.PageImagesPath + savedFileName.Split('/').Last(); slider.SliderImageFileName = file.FileName; } curPage2.EfarganPagesSliders.Add(slider); } } } //update / add to paragraphs if (curPage.EfarganPagesParagraphs.Count > 0) { foreach (var paragraph in curPage.EfarganPagesParagraphs) { //get file data var file = Request.Files["ParagraphImage_" + paragraph.Id]; var savedFileName = ""; if (file != null && file.ContentLength > 0) //need to save a new file { //delete old file if file already exist if (paragraph.ParagraphImageURL != null && !string.IsNullOrEmpty(paragraph.ParagraphImageURL) && paragraph.ParagraphImageFileName != null && !string.IsNullOrEmpty(paragraph.ParagraphImageFileName)) { var oldFileName = paragraph.ParagraphImageURL.Split('/').Last(); var savedToDirectory = AppDomain.CurrentDomain.BaseDirectory + AdminEfarganHelper.PageImagesPath; var savedOldFilePath = savedToDirectory + "/" + oldFileName; System.IO.File.Delete(savedOldFilePath); } savedFileName = AdminEfarganHelper.SavePageImage(file); } //add / update paragraph data var paragraphToUpdate = curPage2.EfarganPagesParagraphs.FirstOrDefault(sl => sl.Id == paragraph.Id); if (paragraphToUpdate != null) { paragraphToUpdate.ParagraphTitle = paragraph.ParagraphTitle; paragraphToUpdate.ParagraphText = paragraph.ParagraphText; paragraphToUpdate.ParagraphLinkText = paragraph.ParagraphLinkText; paragraphToUpdate.ParagraphLinkURL = paragraph.ParagraphLinkURL; paragraphToUpdate.ParagraphImageFileName = paragraph.ParagraphImageFileName; if (file != null && file.ContentLength > 0) //need to save a new file { paragraphToUpdate.ParagraphImageURL = AdminEfarganHelper.PageImagesPath + savedFileName.Split('/').Last(); paragraphToUpdate.ParagraphImageFileName = file.FileName; } } else if (paragraph.Id == -1 && ( !string.IsNullOrEmpty(paragraph.ParagraphTitle) || !string.IsNullOrEmpty(paragraph.ParagraphText) || !string.IsNullOrEmpty(paragraph.ParagraphLinkText) || !string.IsNullOrEmpty(paragraph.ParagraphLinkURL) || !string.IsNullOrEmpty(paragraph.ParagraphImageFileName) )) //add new slider to list { if (file != null && file.ContentLength > 0) //need to save a new file { paragraph.ParagraphImageURL = AdminEfarganHelper.PageImagesPath + savedFileName.Split('/').Last(); paragraph.ParagraphImageFileName = file.FileName; } curPage2.EfarganPagesParagraphs.Add(paragraph); } } } //update / add to tickets if (curPage.EfarganPagesTickers.Count > 0) { foreach (var ticker in curPage.EfarganPagesTickers) { var tickerToUpdate = curPage2.EfarganPagesTickers.FirstOrDefault(sl => sl.Id == ticker.Id); if (tickerToUpdate != null) { tickerToUpdate.TickerTitle = ticker.TickerTitle; tickerToUpdate.TickerText = ticker.TickerText; tickerToUpdate.TickerLinkText = ticker.TickerLinkText; tickerToUpdate.TickerLinkURL = ticker.TickerLinkURL; } else if (ticker.Id == -1 && ( !string.IsNullOrEmpty(ticker.TickerTitle) || !string.IsNullOrEmpty(ticker.TickerText) || !string.IsNullOrEmpty(ticker.TickerLinkText) || !string.IsNullOrEmpty(ticker.TickerLinkURL) )) //add new slider to list { curPage2.EfarganPagesTickers.Add(ticker); } } } //update / add to page language if (curPage.EfarganPagesLanguage.Count > 0) { int i = 0; foreach (var pagesLanguage in curPage.EfarganPagesLanguage) { var pagesLanguageToUpdate = curPage2.EfarganPagesLanguage.FirstOrDefault(lng => lng.Id == pagesLanguage.Id); if (pagesLanguageToUpdate != null) { pagesLanguageToUpdate.TitleTag = pagesLanguage.TitleTag; pagesLanguageToUpdate.MetaTag = pagesLanguage.MetaTag; pagesLanguageToUpdate.DescriptionTag = pagesLanguage.DescriptionTag; pagesLanguageToUpdate.MenuText = pagesLanguage.MenuText; pagesLanguageToUpdate.TicketTitle = pagesLanguage.TicketTitle; pagesLanguageToUpdate.TicketLinkText = pagesLanguage.TicketLinkText; pagesLanguageToUpdate.TicketLinkURL = pagesLanguage.TicketLinkURL; pagesLanguageToUpdate.EfarganLanguage = pagesLanguage.EfarganLanguage; //get page language var LanguageValue = Request.Form["EfarganPagesLanguage[" + i + "].SiteLanguages"]; var curLang = db.EfarganLanguage.FirstOrDefault(lng => lng.LanguageValue == LanguageValue); if (curLang != null) { pagesLanguageToUpdate.EfarganLanguage = curLang; } i++; } else if (pagesLanguage.Id == -1 && ( !string.IsNullOrEmpty(pagesLanguage.TitleTag) || !string.IsNullOrEmpty(pagesLanguage.MetaTag) || !string.IsNullOrEmpty(pagesLanguage.DescriptionTag) || !string.IsNullOrEmpty(pagesLanguage.MenuText) || !string.IsNullOrEmpty(pagesLanguage.TicketTitle) || !string.IsNullOrEmpty(pagesLanguage.TicketLinkText) || !string.IsNullOrEmpty(pagesLanguage.TicketLinkURL) )) //add new slider to list { //get page language var LanguageValue = Request.Form["EfarganPagesLanguage[" + i + "].SiteLanguages"]; var curLang = db.EfarganLanguage.FirstOrDefault(lng => lng.LanguageValue == LanguageValue); if (curLang != null) { pagesLanguage.EfarganLanguageRef = curLang.Id; } curPage2.EfarganPagesLanguage.Add(pagesLanguage); i++; } } } } db.Entry(curPage2).State = EntityState.Modified; db.SaveChanges(); ModelState.Clear(); return(View(curPage2)); } return(RedirectToAction("EfarganPages")); }
public ActionResult EfarganPagesLanguageEdit(EfarganPages curPage, int id, string itemType, int itemCount) { var db = new CustomMembershipDB(); var curPage2 = db.EfarganPagesLanguage.SingleOrDefault(efl => efl.Id == id); if (curPage2 == null) { //db.EfarganPages.Add(curPage); return(RedirectToAction("EfarganPages")); } else { for (int i = 0; i < itemCount; i++) { switch (itemType) { case "Sliders": //get slider data var SliderId = int.Parse(Request.Form["EfarganPagesLanguage.item.EfarganPagesSliders[" + i + "].Id"]); var SliderTitle = Request.Form["EfarganPagesLanguage.item.EfarganPagesSliders[" + i + "].SliderTitle"]; var SliderText = Request.Form["EfarganPagesLanguage.item.EfarganPagesSliders[" + i + "].SliderText"]; var SliderLinkText = Request.Form["EfarganPagesLanguage.item.EfarganPagesSliders[" + i + "].SliderLinkText"]; var SliderLinkURL = Request.Form["EfarganPagesLanguage.item.EfarganPagesSliders[" + i + "].SliderLinkURL"]; var SliderImageFileName = Request.Form["EfarganPagesLanguage.item.EfarganPagesSliders[" + i + "].SliderImageFileName"]; var SliderImageURL = Request.Form["EfarganPagesLanguage.item.EfarganPagesSliders[" + i + "].SliderImageURL"]; //get file data var file = Request.Files["SliderImage_" + SliderId]; var savedFileName = ""; if (file != null && file.ContentLength > 0) //need to save a new file { //delete old file if file already exist if (!string.IsNullOrEmpty(SliderImageFileName) && !string.IsNullOrEmpty(SliderImageURL)) { var oldFileName = SliderImageURL.Split('/').Last(); var savedToDirectory = AppDomain.CurrentDomain.BaseDirectory + AdminEfarganHelper.PageImagesPath; var savedOldFilePath = savedToDirectory + "/" + oldFileName; System.IO.File.Delete(savedOldFilePath); } savedFileName = AdminEfarganHelper.SavePageImage(file); } //add / update slider data if (!string.IsNullOrEmpty(SliderTitle) || !string.IsNullOrEmpty(SliderText) || !string.IsNullOrEmpty(SliderLinkText) || !string.IsNullOrEmpty(SliderLinkURL)) { EfarganPagesSliders curSlider; if (SliderId == -1) { curSlider = new EfarganPagesSliders(); curPage2.EfarganPagesSliders.Add(curSlider); } else { curSlider = curPage2.EfarganPagesSliders.FirstOrDefault(s => s.Id == SliderId); } curSlider.SliderTitle = SliderTitle; curSlider.SliderText = SliderText; curSlider.SliderLinkText = SliderLinkText; curSlider.SliderLinkURL = SliderLinkURL; if (file != null && file.ContentLength > 0) //need to save a new file { curSlider.SliderImageURL = AdminEfarganHelper.PageImagesPath + savedFileName.Split('/').Last(); curSlider.SliderImageFileName = file.FileName; } } break; case "Paragraphs": //get paragraph data var ParagraphId = int.Parse(Request.Form["EfarganPagesLanguage.item.EfarganPagesParagraphs[" + i + "].Id"]); var ParagraphTitle = Request.Form["EfarganPagesLanguage.item.EfarganPagesParagraphs[" + i + "].ParagraphTitle"]; var ParagraphText = Request.Form["EfarganPagesLanguage.item.EfarganPagesParagraphs[" + i + "].ParagraphText"]; var ParagraphLinkText = Request.Form["EfarganPagesLanguage.item.EfarganPagesParagraphs[" + i + "].ParagraphLinkText"]; var ParagraphLinkURL = Request.Form["EfarganPagesLanguage.item.EfarganPagesParagraphs[" + i + "].ParagraphLinkURL"]; var ParagraphImageFileName = Request.Form["EfarganPagesLanguage.item.EfarganPagesParagraphs[" + i + "].ParagraphImageFileName"]; var ParagraphImageURL = Request.Form["EfarganPagesLanguage.item.EfarganPagesParagraphs[" + i + "].ParagraphImageURL"]; //get file data var file2 = Request.Files["ParagraphImage_" + ParagraphId]; var savedFileName2 = ""; if (file2 != null && file2.ContentLength > 0) //need to save a new file { //delete old file if file already exist if (!string.IsNullOrEmpty(ParagraphImageFileName) && !string.IsNullOrEmpty(ParagraphImageURL)) { var oldFileName = ParagraphImageURL.Split('/').Last(); var savedToDirectory = AppDomain.CurrentDomain.BaseDirectory + AdminEfarganHelper.PageImagesPath; var savedOldFilePath = savedToDirectory + "/" + oldFileName; System.IO.File.Delete(savedOldFilePath); } savedFileName2 = AdminEfarganHelper.SavePageImage(file2); } if (!string.IsNullOrEmpty(ParagraphTitle) || !string.IsNullOrEmpty(ParagraphText) || !string.IsNullOrEmpty(ParagraphLinkText) || !string.IsNullOrEmpty(ParagraphLinkURL)) { EfarganPagesParagraphs curParagraph; if (ParagraphId == -1) { curParagraph = new EfarganPagesParagraphs(); curPage2.EfarganPagesParagraphs.Add(curParagraph); } else { curParagraph = curPage2.EfarganPagesParagraphs.FirstOrDefault(p => p.Id == ParagraphId); } curParagraph.ParagraphTitle = ParagraphTitle; curParagraph.ParagraphText = ParagraphText; curParagraph.ParagraphLinkText = ParagraphLinkText; curParagraph.ParagraphLinkURL = ParagraphLinkURL; if (file2 != null && file2.ContentLength > 0) //need to save a new file { curParagraph.ParagraphImageURL = AdminEfarganHelper.PageImagesPath + savedFileName2.Split('/').Last(); curParagraph.ParagraphImageFileName = file2.FileName; } } break; case "Tickers": var TickerId = int.Parse(Request.Form["EfarganPagesLanguage.item.EfarganPagesTickers[" + i + "].Id"]); var TickerTitle = Request.Form["EfarganPagesLanguage.item.EfarganPagesTickers[" + i + "].TickerTitle"]; var TickerText = Request.Form["EfarganPagesLanguage.item.EfarganPagesTickers[" + i + "].TickerText"]; var TickerLinkText = Request.Form["EfarganPagesLanguage.item.EfarganPagesTickers[" + i + "].TickerLinkText"]; var TickerLinkURL = Request.Form["EfarganPagesLanguage.item.EfarganPagesTickers[" + i + "].TickerLinkURL"]; if (!string.IsNullOrEmpty(TickerTitle) || !string.IsNullOrEmpty(TickerText) || !string.IsNullOrEmpty(TickerLinkText) || !string.IsNullOrEmpty(TickerLinkURL)) { EfarganPagesTickers curTicker; if (TickerId == -1) { curTicker = new EfarganPagesTickers(); curPage2.EfarganPagesTickers.Add(curTicker); } else { curTicker = curPage2.EfarganPagesTickers.FirstOrDefault(p => p.Id == TickerId); } curTicker.TickerTitle = TickerTitle; curTicker.TickerText = TickerText; curTicker.TickerLinkText = TickerLinkText; curTicker.TickerLinkURL = TickerLinkURL; } break; default: break; } } } db.Entry(curPage2).State = EntityState.Modified; db.SaveChanges(); ModelState.Clear(); return(RedirectToAction("EfarganPagesEdit", new { curPage = curPage, id = curPage2.EfarganPages.Id })); }
public ActionResult AddNew(FAQModel model) { if (ModelState.IsValid) { try { //prepere question var question = HttpUtility.UrlDecode(model.Question, System.Text.Encoding.Default); question = question.Replace("/Temporary", ""); //new file location model.ImageNames = model.ImageNames[0].Split(','); //add new FAQ to db int? QUserId = null; string NotifyEmail = model.NotifyEmail; CustomMembershipDB db = new CustomMembershipDB(); var curUserId = db.Users.SingleOrDefault(u => u.UserName.Equals(User.Identity.Name)); if (curUserId != null) { QUserId = curUserId.UserId; NotifyEmail = String.IsNullOrEmpty(model.NotifyEmail) ? curUserId.Email : model.NotifyEmail; } var newFAQ = new FAQ { QUserId = QUserId, Date = DateTime.Now, Title = model.Title, Question = question, NotifyByEmail = model.NotifyByEmail, NotifyEmail = NotifyEmail, Active = true }; db.FAQ.Add(newFAQ); //check if all uploaded images appear in question Helper.CheckQuestionImages(dirName, question, model.ImageNames); //add images data foreach (var imageName in model.ImageNames) { db.Images.Add(new Images { FAQ = newFAQ, Name = imageName }); } db.SaveChanges(); //work with files Helper.MoveFiles(dirName, model.ImageNames); ViewBag.AddQuestionStatus = "Question added."; return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError("", "There was an error during save of question."); return(View()); } } else { return(View()); } }
public ActionResult GalleryPagesAddNew(GalleryPages newPage) { var db = new CustomMembershipDB(); var form = Request.Form; var i = 0; while (form["GalleryImages[" + i + "].Id"] != null) { var imageId = int.Parse(form["GalleryImages[" + i + "].Id"]); var imageAlt = form["GalleryImages[" + i + "].Alt"]; var imageBottomText = form["GalleryImages[" + i + "].BottomText"]; var curGalleryImage = db.GalleryImages.SingleOrDefault(g => g.Id == imageId); if (curGalleryImage != null) { curGalleryImage.Alt = imageAlt; curGalleryImage.BottomText = imageBottomText; newPage.GalleryImages.Add(curGalleryImage); } i++; } if (ModelState.IsValid) { //upload files var saveToDirectory = AppDomain.CurrentDomain.BaseDirectory + "Images/Gallery Pages/"; var uploadedMultipleFiles = new List <string>(); foreach (string file in Request.Files) { var multipleFiles = Request.Files.GetMultiple(file); if (multipleFiles.Count > 1 && !uploadedMultipleFiles.Contains(file)) //multiple uploaded files { var curGalleryId = 1; if (db.GalleryPages.Count() > 0) { curGalleryId = db.GalleryPages.Max(p => p.Id) + 1; } var imagePath = "Gallery " + curGalleryId + "/"; var saveToDirectoryMult = saveToDirectory + imagePath; foreach (var item in multipleFiles) { if (item.ContentLength == 0 || uploadedMultipleFiles.Contains(file)) { continue; } var saveFileName = AdminHelper.ClearStrForDBSave(item.FileName); if (!Directory.Exists(saveToDirectoryMult)) { Directory.CreateDirectory(saveToDirectoryMult); } saveFileName = AdminHelper.GetUniqueFileName(saveToDirectoryMult, saveFileName); string savedFileName = Path.Combine( saveToDirectoryMult, saveFileName); item.SaveAs(savedFileName); newPage.GalleryImages.Add(new GalleryImages() { Name = saveFileName, Path = imagePath + saveFileName }); } uploadedMultipleFiles.Add(file); //add to list with multiple uploaded group names } else { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0 || uploadedMultipleFiles.Contains(file)) { continue; } var saveFileName = Path.GetFileName(hpf.FileName); saveFileName = AdminHelper.GetUniqueFileName(saveToDirectory, saveFileName); string savedFileName = Path.Combine( saveToDirectory, saveFileName); hpf.SaveAs(savedFileName); if (file.Equals("TitleImage")) { newPage.TitleImage = saveFileName; } else if (file.Equals("BodyImage")) { newPage.BodyImage = saveFileName; } else if (file.Equals("FooterImage")) { newPage.FooterImage = saveFileName; } } } if (newPage.Id == null) { db.GalleryPages.Add(newPage); } else { db.Entry(newPage).State = EntityState.Modified; } db.SaveChanges(); } return(RedirectToAction("GalleryPages")); }