public ActionResult HomePagePreview(int id = 0) { if (id == 0) { return(RedirectToAction("Unauthorised", "Error")); } GroupHomepageLocal Obj = new GroupHomepageLocal(); bool preview = false; if (Request.QueryString != null) { if (Request.QueryString["Preview"] != null) { preview = true; } } var group = db.Groups.Find(id); if (group != null) { var gHomepage = db.GetHomePage(group.GroupID, 0); var y = from x in gHomepage select new GroupHomepageLocal { GroupId = x.GroupID, GroupHomePageId = x.GroupHomepageID == null ? 0 : x.GroupHomepageID, GroupName = x.GroupName, OrganisationName = x.OrganisationName, ImagePosition = x.ImageLocation == null ? (int)1 : (int)x.ImageLocation, PageContent = WebUtility.HtmlDecode(x.HomePageContent), UploadFileUrl = x.ImagePath, IsPreview = preview }; Obj = y.SingleOrDefault(); //if (Obj != null) { Obj.GroupName = group.GroupName; Obj.ImagePosition = string.IsNullOrWhiteSpace(Obj.ImagePosition.ToString()) ? 1 : Obj.ImagePosition; } //else { Obj = new GroupHomepageLocal(); Obj.GroupId = group.GroupID; Obj.OrganisationName = (group.Organisation != null) ? group.Organisation.OrganisationName : ""; Obj.GroupName = group.GroupName; Obj.ImagePosition = 1; } if (Obj == null) { Obj = new GroupHomepageLocal(); Obj.GroupId = group.GroupID; Obj.OrganisationName = (group.Organisation != null) ? group.Organisation.OrganisationName : ""; Obj.GroupName = group.GroupName; Obj.ImagePosition = 1; } } else { return(RedirectToAction("Unauthorised", "Error")); } return(View(Obj)); }
public ActionResult AjaxHandlerGroupHome(int GroupID) { if (GroupID == 0) { return(RedirectToAction("Index", "User")); } int languageId = 0; languageId = int.Parse(Session["LanguageId"].ToString()); GroupHomepageLocal Obj = new GroupHomepageLocal(); bool preview = false; var gHomepage = db.GetHomePage(GroupID, languageId); var y = from x in gHomepage select new GroupHomepageLocal { GroupId = x.GroupID, GroupHomePageId = x.GroupHomepageID == null ? 0 : x.GroupHomepageID, GroupName = x.GroupName, OrganisationName = x.OrganisationName, ImagePosition = x.ImageLocation == null ? (int)0 : (int)x.ImageLocation, PageContent = WebUtility.HtmlDecode(x.HomePageContent), UploadFileUrl = x.ImagePath, IsPreview = preview }; Obj = y.SingleOrDefault(); return(Json(Obj, JsonRequestBehavior.AllowGet)); }
public ActionResult GroupHomePage(GroupHomepageLocal Obj) { if (ModelState.IsValid) { string fileName = ""; var GHomePage = db.GroupHomepages.Where(x => x.GroupID == Obj.GroupId).FirstOrDefault(); if (GHomePage == null) // create new { GroupHomepage Objnew = new GroupHomepage(); #region // Process Course file Save to server folders if (Request.Files.Count > 0) { foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file]; if (hpf.FileName != "") { fileName = hpf.FileName.Split('\\').Last().ToString(); if (Common.IsValidFileName(hpf.FileName.Split('\\').Last().ToString(), true) == false) { ModelState.AddModelError("UploadFileUrl", "error"); //PrepareAvailableLangaugeModel(activity, false); return(View(Obj)); } Guid g = Guid.NewGuid(); Objnew.GroupID = Obj.GroupId; Objnew.ImagePath = ""; Objnew.ImageLocation = Obj.ImagePosition; Objnew.CreationDate = DateTime.Now; Objnew.CreatedById = Convert.ToInt64(Session["UserID"]); db.GroupHomepages.Add(Objnew); db.SaveChanges(); var absImgDir = Path.Combine(Server.MapPath("~") + @"\Content\Uploads\GroupHomepage\", "_" + Objnew.GroupHomepageID.ToString()); Directory.CreateDirectory(absImgDir); var relCourseDir = Path.Combine(@"\Content\Uploads\GroupHomepage\", "_" + Objnew.GroupHomepageID.ToString()); hpf.SaveAs(Path.Combine(absImgDir, @fileName)); Objnew.ImagePath = Path.Combine(relCourseDir, @fileName); db.SaveChanges(); Obj.UploadFileUrl = Objnew.ImagePath; AddEditGroupHomepageInfoRecord(Objnew, Obj.PageContent, 1); } } } #endregion } else { if (Request.Files.Count > 0) { foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file]; if (hpf.FileName != "") { fileName = hpf.FileName.Split('\\').Last().ToString(); if (Common.IsValidFileName(hpf.FileName.Split('\\').Last().ToString(), true) == false) { ModelState.AddModelError("UploadFileUrl", "error"); //PrepareAvailableLangaugeModel(activity, false); return(View(Obj)); } var absImgDir = Path.Combine(Server.MapPath("~") + @"\Content\Uploads\GroupHomepage\", "_" + GHomePage.GroupHomepageID.ToString()); if (!Directory.Exists(absImgDir)) { Directory.CreateDirectory(absImgDir); } var relCourseDir = Path.Combine(@"\Content\Uploads\GroupHomepage\", "_" + GHomePage.GroupHomepageID.ToString()); hpf.SaveAs(Path.Combine(absImgDir, @fileName)); GHomePage.ImagePath = Path.Combine(relCourseDir, @fileName); } } } GHomePage.ImageLocation = Obj.ImagePosition; GHomePage.CreationDate = DateTime.Now; GHomePage.CreatedById = Convert.ToInt64(Session["UserID"]); db.SaveChanges(); Obj.UploadFileUrl = GHomePage.ImagePath; AddEditGroupHomepageInfoRecord(GHomePage, Obj.PageContent, 1); } } else { return(View(Obj)); } if (Obj.IsPreview == true) { return(RedirectToAction("GroupHomePage", "Groups", new { id = Obj.GroupId, @Preview = "y" })); } else { return(RedirectToAction("GroupHomePage", "Groups", new { id = Obj.GroupId })); } //return View(Obj); }