public ActionResult Edit(int id, PostModels p, HttpPostedFileBase Image) { if (!ModelState.IsValid || Image == null || Image.ContentLength == 0) { RedirectToAction("Edit"); } //if (Image.FileName==null) //{ // Image.FileName = "default.png"; //} p.Image = Image.FileName; Post post = ps.GetById(id); post.Title = p.Title; post.Description = p.Description; post.Privacy = p.Privacy; post.Image = p.Image; post.PostDateTime = DateTime.Now; ps.Update(post); ps.Commit(); var path = Path.Combine(Server.MapPath("~/Content/images/"), Image.FileName); Image.SaveAs(path); return(RedirectToAction("Index")); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostModels pst = db.Posts.Find(id); var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); var author = manager.FindById(pst.UserID); var viewpost = new IdentityPostViewModel() { category = pst.category, UserFullName = author.Name + " " + author.Surname, content = pst.content, dateCreated = pst.dateCreated, postID = pst.postID, title = pst.title, UserID = pst.UserID, lastModified = pst.lastModified }; if (pst == null) { return(HttpNotFound()); } return(View(viewpost)); }
public ActionResult Create(PostModels p, HttpPostedFileBase Image) { if (!ModelState.IsValid || Image == null || Image.ContentLength == 0) { RedirectToAction("Create"); } p.Image = Image.FileName; try { Post post = new Post { PostId = p.Id, Title = p.Title, Description = p.Description, Privacy = p.Privacy, Image = p.Image, PostDateTime = DateTime.Now }; ps.Add(post); ps.Commit(); //ps.Dispose(); var path = Path.Combine(Server.MapPath("~/Content/images/"), Image.FileName); Image.SaveAs(path); return(RedirectToAction("Index")); } catch { return(View()); } }
public void AddPost(PostModels post) { if (ModelState.IsValid) { string postTo; if (string.IsNullOrWhiteSpace(post.PostToId)) { postTo = User.Identity.GetUserId(); } else { postTo = post.PostToId; } PostModels postModel = new PostModels() { Text = post.Text, PostFromId = User.Identity.GetUserId(), PostToId = postTo, PostDateTime = DateTime.Now }; postRepository.Add(postModel); postRepository.Save(); } }
public ActionResult DeleteConfirmed(int id) { PostModels postmodels = db.Posts.Find(id); db.Posts.Remove(postmodels); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "PostId,Title,PostContent")] PostModels postModel) { if (ModelState.IsValid) { _postRepository.Edit(postModel); return(RedirectToLocal("PostList")); } return(View(postModel)); }
// // GET: /Post/Edit/5 public ActionResult Edit(int id = 0) { PostModels postmodels = db.Posts.Find(id); if (postmodels == null) { return(HttpNotFound()); } return(View(postmodels)); }
public ActionResult Post_list_hot(int?cate_id) { PostModels postModels = new PostModels(); List <C_Post> listPost = new List <C_Post>(); postModels.ClearCache(CommonGlobal.Post + CommonGlobal.CateNews + LanguageModels.ActiveLanguage().LangCultureName + int.Parse(Util.GetConfigValue("NumberListLatestNews", "0"))); listPost = postModels.TopPostHot(CommonGlobal.CateNews, cate_id, LanguageModels.ActiveLanguage().LangCultureName, int.Parse(Util.GetConfigValue("NumberListLatestNews", "0"))); return(this.PartialView("../control/post_list_hot", listPost)); }
public async Task DeleteMessage(Guid postId, HttpClient httpClient) { await httpClient.DeleteAsync($"Post/{postId}"); var deletedMessage = PostModels.FirstOrDefault(postModel => postModel.PostId == postId); PostModels.Remove(deletedMessage); ChangePost?.Invoke(); }
public ActionResult Edit(PostModels postmodels) { if (ModelState.IsValid) { db.Entry(postmodels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(postmodels)); }
public ActionResult Create(int Type, String Title, String Tag, String Lead, String Context) { if (Type == 0) { var Emergency = new EmergencyNewsModels(); Emergency.Title = Title; Emergency.Tag = Tag; Emergency.Lead = Lead; Emergency.Context = Context; Emergency.CreatedDate = DateTime.Now; Emergency.School = SchoolID; Emergency.Delete = 0; Emergency.PostBy = "TA"; db.Emergency.Add(Emergency); db.SaveChanges(); } else if (Type == 1) { var New = new NewsClassModels(); New.Title = Title; New.Tag = Tag; New.Lead = Lead; New.Context = Context; New.CreatedDate = DateTime.Now; New.School = SchoolID; New.Delete = 0; New.PostBy = "TA"; db.NewsClass.Add(New); db.SaveChanges(); } else if (Type == 2) { var Post = new PostModels(); Post.Title = Title; Post.Tag = Tag; Post.Lead = Lead; Post.Context = Context; Post.CreatedDate = DateTime.Now; Post.School = SchoolID; Post.Delete = 0; Post.PostBy = "TA"; db.Post.Add(Post); db.SaveChanges(); } return(RedirectToAction("TAIndex")); }
/// <summary> /// Updates the status is hot post. /// </summary> /// <param name="id">The identifier.</param> /// <param name="status">The status.</param> /// <param name="type">The type.</param> /// <returns>update status is hot post</returns> public ActionResult Update_status_is_hot_post(string id, string status, string type) { PostModels postModel = new PostModels(); C_Post objPost = new C_Post(); bool isOk = false; if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, "change_post", "adminPost", CommonGlobal.Edit, type)) { isOk = true; } else { isOk = false; } if (!string.IsNullOrEmpty(id)) { if (int.Parse(id) > 0) { objPost = postModel.GetbyID(int.Parse(id)); } if (objPost != null) { try { if (bool.Parse(status) == true) { objPost.IsHot = true; } else { objPost.IsHot = false; } if (isOk) { objPost.DateModified = DateTime.Now; postModel.Edit(objPost); } } catch (Exception) { } } } var jsonSerialiser = new JavaScriptSerializer(); var results = Convert.ToDateTime(DateTime.Now).ToString("dd/MM/yyyy") + "|" + objPost.IsHot; return(this.Json(results)); }
public ActionResult CreateAnswer(Answer answer) { if (ModelState.IsValid) { PostModels postmodel = db.Posts.Find(answer.Id); answer.PosModelsId = postmodel.Id; postmodel.Answers.Add(answer); // db.Answers.Add(answer); db.SaveChanges(); return(RedirectToAction("ViewAnswers", new{ id = answer.PosModelsId })); } return(View(answer)); }
// GET: Post/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostModels posts = db.Posts.Find(id); if (posts == null) { return(HttpNotFound()); } return(View(posts)); }
public ResultSet deletePost(PostModels PM) { try { var postId = new SqlParameter("@postId", PM.PostId); return(Context.Database.SqlQuery <ResultSet>(@"EXEC sp_delete_post postId=@postId", postId).FirstOrDefault()); } catch (Exception ex) { return(new ResultSet() { code = 0, message = ex.Message }); } }
public ActionResult Create(PostModels postmodels) { if (ModelState.IsValid) { CategoryTopic categoryTopic = db.CategoryTopics.Find(postmodels.CategoryId); postmodels.PosterName = User.Identity.Name; postmodels.DateSubmit = DateTime.Now.Date; categoryTopic.PostModelses.Add(postmodels); // db.Posts.Add(postmodels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(postmodels)); }
public HttpResponseMessage GetPost(string method, PostModels post) { try { using (var provider = new PostProvider()) { return(Request.CreateResponse(HttpStatusCode.OK, provider.getAll())); } } catch (Exception ex) { result.code = 0; result.message = ex.Message; return(Request.CreateResponse(HttpStatusCode.InternalServerError, result)); } }
public ResultSet createPost(PostModels PM) { try { var postTitle = new SqlParameter("@postTitle", PM.PostTitle); var postDescription = new SqlParameter("@postDescription", PM.PostDescription); return(Context.Database.SqlQuery <ResultSet>(@"EXEC sp_create_post postTitle=@postTitle,postDescription=@postDescription", postTitle, postDescription).FirstOrDefault()); } catch (Exception ex) { return(new ResultSet() { code = 0, message = ex.Message }); } }
public ActionResult Create([Bind(Include = "postID,title,content,category,status,dateCreated,lastModified")] PostModels posts) { //The following two lines automatically sets date created & modified variables to the current date & time posts.dateCreated = DateTime.Now; posts.lastModified = DateTime.Now; posts.UserID = User.Identity.GetUserId(); if (ModelState.IsValid) { db.Posts.Add(posts); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(posts)); }
// GET: Post/Details/5 public ActionResult Details(int id) { Post post = ps.GetById(id); PostModels p = new PostModels { Id = post.PostId, Title = post.Title, Description = post.Description, Image = post.Image, Privacy = post.Privacy, PostDateTime = post.PostDateTime }; if (p == null) { return(HttpNotFound()); } return(View(p)); }
public ActionResult Edit(int?id, PostModels post) { if (!id.HasValue) { return(null); } var dbpost = DbContext.Posts.Where(p => p.Id == id).Include(p => p.PostedForum).Include(p => p.SenderId).FirstOrDefault(); if (dbpost == null) { return(null); } if (!(User.Identity.GetUserId() == dbpost.SenderId.Id || User.IsInRole("Admin"))) { return(null); } dbpost.Content = post.Content; DbContext.SaveChanges(); return(RedirectToAction("Index", "Forum", new { id = dbpost.PostedForum.Id })); }
public HttpResponseMessage update([FromBody] PostModels PM) { try { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new ResultSet() { code = 0, message = "Bad Request" })); } using (var provider = new PostProvider()) { return(Request.CreateResponse(HttpStatusCode.OK, provider.updatePost(PM))); } } catch (Exception ex) { result.code = 0; result.message = ex.Message; return(Request.CreateResponse(HttpStatusCode.InternalServerError, result)); } }
public ActionResult Post_list_view() { PostModels postModels = new PostModels(); var list_view = new ViewModels.List_post_view(); ArrayList viewLst = new ArrayList(); HttpCookie mycookie = Request.Cookies["listPostView"]; if (mycookie != null) { var arr = mycookie.Value.Split(','); for (int j = arr.Count() - 1; j > 0; j--) { ////max 3 if ((arr.Count() - j) <= 3) { viewLst.Add(arr[j]); } } } if (viewLst.Count <= 0) { list_view.Message = App_GlobalResources.Lang.messErrorWishlist; list_view.ListView = null; list_view.ItemCount = "0"; } else { list_view.Message = string.Empty; list_view.ListView = new ArrayList(postModels.GetListPostView(viewLst)); list_view.ItemCount = postModels.GetListPostView(viewLst).Count.ToString(); } return(this.PartialView("../control/post_list_view", list_view)); }
public ActionResult Post_detail(int?id, int?cate_id, string back_link, string cate_type) { string url = Request.Url.ToString(); RatingModels ratingModels = new RatingModels(); PostModels postModels = new PostModels(); id = RouteData.Values["id"] != null?Convert.ToInt16(RouteData.Values["id"].ToString()) : 0; var post_view = new ViewModels.Post_detail_view(); if (id == 0) { return(this.HttpNotFound()); } else { postModels.ClearCache(CommonGlobal.Post + string.Empty + id); C_Post obj = postModels.GetbyID((int)id); if (obj.PostID == 0) { return(this.HttpNotFound()); } ////post_view.listRating = ratingModels.GetListRatingByItem(obj.PostID); ////StringBuilder _html5 = new StringBuilder(); ////for (int j = 0; j < post_view.listRating.Count; j++) ////{ //// _html5.Append("<div class=\"review-header\">"); //// _html5.Append(" <h5>" + HttpUtility.HtmlDecode(post_view.listRating[j].name) + "</h5>"); //// _html5.Append(" <div class=\"product-rating\">"); //// _html5.Append(" <div class=\"stars\">"); //// var start = post_view.listRating[j].Rating ?? 0; //// var other = 5 - start; //// for (int jj = 0; jj < other; jj++) //// { //// _html5.Append("<span class=\"star\"></span>"); //// } //// for (int ii = 0; ii < start; ii++) //// { //// _html5.Append("<span class=\"star active\"></span>"); //// } //// _html5.Append(" </div>"); //// _html5.Append(" </div>"); //// _html5.Append("</div>"); //// _html5.Append("<div class=\"review-body\">"); //// _html5.Append(" <p>" + HttpUtility.HtmlDecode(post_view.listRating[j].contents) + "</p>"); //// _html5.Append("</div>"); //// _html5.Append("<hr>"); ////} ////post_view.ltrRating = _html5.ToString(); ////post_view.ratingSum = ratingModels.GetRatingSumforItem(obj.PostID); ////post_view.ratingTotal = ratingModels.GetRatingTotalforItem(obj.PostID); ////StringBuilder _html6 = new StringBuilder(); ////var start_no = post_view.ratingTotal != 0 ? (post_view.ratingSum / post_view.ratingTotal) : 0; ////var other_no = 5 - start_no; ////for (int jj = 0; jj < other_no; jj++) ////{ //// _html6.Append("<span class=\"star\"></span>"); ////} ////for (int ii = 0; ii < start_no; ii++) ////{ //// _html6.Append("<span class=\"star active\"></span>"); ////} ////post_view.ratingStart = _html6.ToString(); post_view.ListOther = postModels.GetOthers(obj.PostID, obj.CatelogID ?? 0, LanguageModels.ActiveLanguage().LangCultureName, int.Parse(Util.GetConfigValue("NumberOtherNews", "3"))); CatalogModels catalogModel = new CatalogModels(); C_Catalog cateItem = new C_Catalog(); if (cate_id == 0) { if (obj.CatelogID != null && obj.CatelogID != 0) { cate_id = obj.CatelogID; } } cateItem = catalogModel.GetbyID((int)cate_id); post_view.PostID = obj.PostID; post_view.PostName = obj.PostName; post_view.Title = obj.Title; post_view.Summary = CommonGlobal.CutString(obj.Summary, 500); post_view.CatalogID = obj.CatelogID; post_view.ImagePath = obj.ImagePath; post_view.Link = obj.Link; post_view.PostContent = obj.PostContent; post_view.DateModified = obj.DateModified; post_view.IsHot = obj.IsHot; post_view.Lang = obj.Lang; post_view.Keyword = obj.Keyword; post_view.Description = obj.Description; post_view.OrderDisplay = obj.OrderDisplay; post_view.Approve = obj.Approve; post_view.Cate_id = cate_id ?? 0; post_view.Cate_type = cate_type; post_view.Url = url; } return(this.PartialView("../control/post_detail", post_view)); }
public static void SeedUsers(ApplicationDbContext context) { // Create the users UserStore <ApplicationUser> store = new UserStore <ApplicationUser>(context); UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(store); ApplicationUser eliasU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(eliasU, "password"); ApplicationUser nicoU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(nicoU, "password"); ApplicationUser oskarU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(oskarU, "password"); ApplicationUser randomU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(randomU, "password"); ApplicationUser corazonU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(corazonU, "password"); ApplicationUser andreasU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(andreasU, "password"); ApplicationUser mathiasU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(mathiasU, "password"); ApplicationUser lightU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(lightU, "password"); ApplicationUser hakU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(hakU, "password"); ApplicationUser alfonsU = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; manager.Create(alfonsU, "password"); // Define Profiles ProfileModels eliasP = new ProfileModels { Id = eliasU.Id, FirstName = "Elias", LastName = "Stagg", Gender = Gender.Man, Biography = "This is an example biography of the profile for Elias Stagg.", BirthDate = new DateTime(1998, 04, 22), Desperation = 10, Loneliness = 10, Horniness = 4, Pride = 6, ProfileImage = setInitializerProfilePicture("/Content/Images/stagg.jpg") }; ProfileModels nicoP = new ProfileModels { Id = nicoU.Id, FirstName = "Nicolas", LastName = "Björkefors", Gender = Gender.Man, Biography = "This is an example biography of the profile for Nicolas Björkefors.", BirthDate = new DateTime(1998, 01, 05), Desperation = 9, Loneliness = 10, Horniness = 3, Pride = 8, ProfileImage = setInitializerProfilePicture("/Content/Images/smugOkuu.png") }; ProfileModels oskarP = new ProfileModels { Id = oskarU.Id, FirstName = "Oskar", LastName = "Olofsson", Gender = Gender.Man, Biography = "This is an example biography of the profile for Oskar Olofsson.", BirthDate = new DateTime(1982, 09, 15), Desperation = 9, Loneliness = 10, Horniness = 10, Pride = 1, ProfileImage = setInitializerProfilePicture("/Content/Images/pickadoller.jpg") }; ProfileModels randomP = new ProfileModels { Id = randomU.Id, FirstName = "Random", LastName = "Svensson", Gender = Gender.Attackhelicopter, Biography = "This is an example biography of the profile for Random Svensson.", BirthDate = new DateTime(1980, 08, 14), Desperation = 5, Loneliness = 6, Horniness = 10, Pride = 9, ProfileImage = setInitializerProfilePicture("/Content/Images/random.png") }; ProfileModels corazonP = new ProfileModels { Id = corazonU.Id, FirstName = "Corazon", LastName = "D'amico", Gender = Gender.Man, Biography = "Este es un ejemplo de biografía del perfil de Corazon D'amico.", BirthDate = new DateTime(1971, 07, 15), Desperation = 10, Loneliness = 10, Horniness = 7, Pride = 3, ProfileImage = setInitializerProfilePicture("/Content/Images/corazon.png") }; ProfileModels andreasP = new ProfileModels { Id = andreasU.Id, FirstName = "Andreas", LastName = "Ask", Gender = Gender.Man, Biography = "Ja, nu har du hittat min profil. Diskutera vad detta innebär sakligt i par eller nåt. Och förresten har någon sett min fez?", BirthDate = new DateTime(1900, 01, 25), Desperation = 8, Loneliness = 10, Horniness = 7, Pride = 5, ProfileImage = setInitializerProfilePicture("/Content/Images/ask.jpg") }; ProfileModels mathiasP = new ProfileModels { Id = mathiasU.Id, FirstName = "Mathias", LastName = "Hatakka", Gender = Gender.Man, Biography = "Jag har en katt, och katten. Har flera katter. Mitt hem är praktiskt taget ett katthem.", BirthDate = new DateTime(1900, 05, 11), Desperation = 5, Loneliness = 10, Horniness = 7, Pride = 8, ProfileImage = setInitializerProfilePicture("/Content/Images/katt.jpg") }; ProfileModels lightP = new ProfileModels { Id = lightU.Id, FirstName = "月", LastName = "夜神", Gender = Gender.Man, Biography = "を魚取り、ヌードリングする", BirthDate = new DateTime(1996, 03, 22), Desperation = 3, Loneliness = 10, Horniness = 7, Pride = 10, ProfileImage = setInitializerProfilePicture("/Content/Images/light.png") }; ProfileModels hakP = new ProfileModels { Id = hakU.Id, FirstName = "Hak", LastName = "Son", Gender = Gender.Man, Biography = "Don't come near me or the princess. I'll kill you.", BirthDate = new DateTime(1982, 09, 29), Desperation = 2, Loneliness = 10, Horniness = 8, Pride = 10, ProfileImage = setInitializerProfilePicture("/Content/Images/hak.png") }; ProfileModels alfonsP = new ProfileModels { Id = alfonsU.Id, FirstName = "Alfons", LastName = "Åberg", Gender = Gender.Man, Biography = "Någon som vill med på brajbaxningsäventyr?", BirthDate = new DateTime(2002, 12, 11), Desperation = 6, Loneliness = 10, Horniness = 4, Pride = 10, ProfileImage = setInitializerProfilePicture("/Content/Images/braj.png") }; // Define Posts PostModels post1 = new PostModels { PostFromId = eliasU.Id, PostToId = randomU.Id, PostDateTime = new DateTime(2019, 01, 12, 14, 44, 24), Text = "Praise RNGesus!" }; PostModels post2 = new PostModels { PostFromId = oskarU.Id, PostToId = randomU.Id, PostDateTime = new DateTime(2019, 01, 13, 23, 45, 02), Text = "Shit asså." }; PostModels post3 = new PostModels { PostFromId = nicoU.Id, PostToId = randomU.Id, PostDateTime = new DateTime(2019, 01, 14, 19, 01, 08), Text = "Söker efter någon att spela Pokémon Reborn med!" }; PostModels post4 = new PostModels { PostFromId = randomU.Id, PostToId = randomU.Id, PostDateTime = new DateTime(2019, 01, 15, 17, 33, 48), Text = "Does this thing work?" }; PostModels post5 = new PostModels { PostFromId = nicoU.Id, PostToId = corazonU.Id, PostDateTime = new DateTime(2019, 01, 15, 07, 27, 33), Text = "I'm your biggest fan!" }; PostModels post6 = new PostModels { PostFromId = corazonU.Id, PostToId = corazonU.Id, PostDateTime = new DateTime(2019, 01, 15, 08, 03, 17), Text = "Gracias." }; PostModels post7 = new PostModels { PostFromId = corazonU.Id, PostToId = eliasU.Id, PostDateTime = new DateTime(2019, 01, 16, 17, 28, 51), Text = "Hola señor." }; PostModels post8 = new PostModels { PostFromId = oskarU.Id, PostToId = nicoU.Id, PostDateTime = new DateTime(2019, 01, 18, 22, 04, 55), Text = "Mate, get stuck in there. Scrum!" }; PostModels post9 = new PostModels { PostFromId = eliasU.Id, PostToId = randomU.Id, PostDateTime = new DateTime(2019, 01, 20, 19, 05, 33), Text = "Fett avis på din randomness." }; PostModels post10 = new PostModels { PostFromId = lightU.Id, PostToId = alfonsU.Id, PostDateTime = new DateTime(2019, 01, 22, 21, 09, 53), Text = "死ね、 人間のくず" }; PostModels post11 = new PostModels { PostFromId = alfonsU.Id, PostToId = mathiasU.Id, PostDateTime = new DateTime(2019, 01, 22, 21, 05, 18), Text = "Hej jag vill klappa katter." }; PostModels post12 = new PostModels { PostFromId = andreasU.Id, PostToId = eliasU.Id, PostDateTime = new DateTime(2019, 01, 23, 07, 48, 32), Text = "Kom ihåg att evaluera dina hattalternativ noga varje morgon. Idag valde jag min fez." }; PostModels post13 = new PostModels { PostFromId = mathiasU.Id, PostToId = oskarU.Id, PostDateTime = new DateTime(2019, 01, 24, 11, 39, 33), Text = "En av mina katter har tappat sitt hår. Får jag låna lite av ditt?" }; PostModels post14 = new PostModels { PostFromId = nicoU.Id, PostToId = lightU.Id, PostDateTime = new DateTime(2019, 01, 24, 22, 52, 04), Text = "私はLですwwww." }; PostModels post15 = new PostModels { PostFromId = oskarU.Id, PostToId = alfonsU.Id, PostDateTime = new DateTime(2019, 01, 25, 10, 41, 52), Text = "Har svårt att stå emot en sådan lockande inbjudan! Hänger med på studs." }; PostModels post16 = new PostModels { PostFromId = alfonsU.Id, PostToId = andreasU.Id, PostDateTime = new DateTime(2019, 02, 14, 06, 37, 09), Text = "Eyy, Andy! Ska du med och baxa braj?" }; // Define requests RequestModels request1 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = nicoU.Id, RequestToId = corazonU.Id }; RequestModels request2 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = oskarU.Id, RequestToId = corazonU.Id }; RequestModels request3 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = oskarU.Id, RequestToId = eliasU.Id }; RequestModels request4 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = randomU.Id, RequestToId = eliasU.Id }; RequestModels request5 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = nicoU.Id, RequestToId = lightU.Id }; RequestModels request6 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = lightU.Id, RequestToId = mathiasU.Id }; RequestModels request7 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = randomU.Id, RequestToId = alfonsU.Id }; RequestModels request8 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = alfonsU.Id, RequestToId = eliasU.Id }; RequestModels request9 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = hakU.Id, RequestToId = eliasU.Id }; RequestModels request10 = new RequestModels { RequestDateTime = DateTime.Now, RequestFromId = andreasU.Id, RequestToId = nicoU.Id }; // Define FriendCategories FriendCategoryModels category1 = new FriendCategoryModels { CategoryName = "Default" }; FriendCategoryModels category2 = new FriendCategoryModels { CategoryName = "Acquaintances" }; FriendCategoryModels category3 = new FriendCategoryModels { CategoryName = "BFFs" }; // Define Visits VisitorModels eliasV1 = new VisitorModels { VisitDateTime = new DateTime(2019, 01, 25, 10, 41, 52), VisitFromId = nicoU.Id, VisitToId = eliasU.Id }; VisitorModels eliasV2 = new VisitorModels { VisitDateTime = new DateTime(2019, 05, 15, 12, 54, 8), VisitFromId = oskarU.Id, VisitToId = eliasU.Id }; VisitorModels eliasV3 = new VisitorModels { VisitDateTime = new DateTime(2019, 05, 04, 22, 21, 54), VisitFromId = andreasU.Id, VisitToId = eliasU.Id }; VisitorModels eliasV4 = new VisitorModels { VisitDateTime = new DateTime(2019, 02, 21, 23, 15, 12), VisitFromId = lightU.Id, VisitToId = eliasU.Id }; VisitorModels eliasV5 = new VisitorModels { VisitDateTime = new DateTime(2019, 05, 25, 13, 41, 45), VisitFromId = randomU.Id, VisitToId = eliasU.Id }; VisitorModels nicoV1 = new VisitorModels { VisitDateTime = new DateTime(2019, 05, 25, 13, 41, 45), VisitFromId = randomU.Id, VisitToId = nicoU.Id }; VisitorModels nicoV2 = new VisitorModels { VisitDateTime = new DateTime(2019, 07, 30, 20, 35, 26), VisitFromId = andreasU.Id, VisitToId = nicoU.Id }; VisitorModels nicoV3 = new VisitorModels { VisitDateTime = new DateTime(2019, 08, 25, 14, 37, 55), VisitFromId = lightU.Id, VisitToId = nicoU.Id }; VisitorModels oskarV = new VisitorModels { VisitDateTime = new DateTime(2019, 09, 26, 15, 38, 56), VisitFromId = andreasU.Id, VisitToId = oskarU.Id }; VisitorModels lightV = new VisitorModels { VisitDateTime = new DateTime(2019, 05, 24, 19, 48, 26), VisitFromId = andreasU.Id, VisitToId = lightU.Id }; VisitorModels mathiasV = new VisitorModels { VisitDateTime = new DateTime(2019, 06, 23, 18, 47, 41), VisitFromId = andreasU.Id, VisitToId = mathiasU.Id }; VisitorModels randomV = new VisitorModels { VisitDateTime = new DateTime(2019, 09, 12, 09, 37, 23), VisitFromId = andreasU.Id, VisitToId = randomU.Id }; VisitorModels hakV = new VisitorModels { VisitDateTime = new DateTime(2019, 03, 28, 10, 00, 00), VisitFromId = andreasU.Id, VisitToId = randomU.Id }; VisitorModels andreasV = new VisitorModels { VisitDateTime = new DateTime(2019, 04, 19, 14, 12, 35), VisitFromId = alfonsU.Id, VisitToId = randomU.Id }; VisitorModels alfonsV = new VisitorModels { VisitDateTime = new DateTime(2019, 08, 25, 14, 37, 55), VisitFromId = andreasU.Id, VisitToId = alfonsU.Id }; context.Visitors.AddRange(new[] { eliasV1, eliasV2, eliasV3, eliasV4, eliasV5, nicoV1, nicoV2, nicoV3, oskarV, lightV, mathiasV, randomV, hakV, andreasV, alfonsV }); context.Profiles.AddRange(new[] { eliasP, nicoP, oskarP, randomP, corazonP, andreasP, mathiasP, lightP, hakP, alfonsP }); // Add profiles context.Posts.AddRange(new[] { post1, post2, post3, post4, post5, post6, post7, post8, post9, post10, post11, post12, post13, post14, post15, post16 }); // Add posts context.Requests.AddRange(new[] { request1, request2, request3, request4, request5, request6, request7, request8, request9, request10 }); // Add requests context.Categories.AddRange(new[] { category1, category2, category3 }); // Add friend categories context.SaveChanges(); // We need to save the friend categories into the database to be able to access their IDs for the creation of the friends. // Define friendships FriendModels friends1 = new FriendModels { UserId = nicoU.Id, FriendId = oskarU.Id, FriendCategory = category1.Id }; FriendModels friends2 = new FriendModels { UserId = nicoU.Id, FriendId = eliasU.Id, FriendCategory = category2.Id }; FriendModels friends3 = new FriendModels { UserId = eliasU.Id, FriendId = corazonU.Id, FriendCategory = category3.Id }; FriendModels friends4 = new FriendModels { UserId = oskarU.Id, FriendId = randomU.Id, FriendCategory = category1.Id }; FriendModels friends5 = new FriendModels { UserId = oskarU.Id, FriendId = alfonsU.Id, FriendCategory = category1.Id }; FriendModels friends6 = new FriendModels { UserId = eliasU.Id, FriendId = lightU.Id, FriendCategory = category1.Id }; FriendModels friends7 = new FriendModels { UserId = andreasU.Id, FriendId = eliasU.Id, FriendCategory = category1.Id }; FriendModels friends8 = new FriendModels { UserId = nicoU.Id, FriendId = hakU.Id, FriendCategory = category1.Id }; context.Friends.AddRange(new[] { friends1, friends2, friends3, friends4, friends5, friends6, friends7, friends8 }); // Add friendships context.SaveChanges(); }
public ActionResult Post_list_all(string lang, string cate_type, int?cate_id, string link_text, string search, string tag, string param, int?page, int?page_size, string order, string style_list_show) { CatalogModels cateModels = new CatalogModels(); WebInfoModels web_infor = new Models.WebInfoModels(); int total_record = 0; PostModels postModels = new PostModels(); C_Catalog cate = null; ////request query string param page = Request.QueryString["page"] != null?Convert.ToInt16(Request.QueryString["page"].ToString()) : 1; if (cate_id == null) { cate_id = RouteData.Values["id"] != null?Convert.ToInt16(RouteData.Values["id"].ToString()) : 0; } if (string.IsNullOrEmpty(link_text)) { link_text = RouteData.Values["Link"] != null ? RouteData.Values["Link"].ToString() : string.Empty; } if (cate_id > 0) { cate = cateModels.GetbyID((int)cate_id); } ////get order for product list string order_by = string.Empty; string order_type = string.Empty; if (string.IsNullOrEmpty(order)) { order_by = "DateModified"; order_type = "desc"; order = order_by + ";" + order_type; } else { if (order.Contains(';')) { order_by = order.Split(';')[0]; order_type = order.Split(';')[1]; } else { order_by = "DateModified"; order_type = "desc"; order = order_by + ";" + order_type; } } postModels.ClearCache(lang + cate_type + (cate_id ?? 0) + search + tag + param + page + page_size + order_by + order_type); List <SelectListItem> orderDrop = new List <SelectListItem>(); orderDrop.AddRange(new SelectListItem[] { new SelectListItem { Selected = order == "DateModified;desc" ? true : false, Text = App_GlobalResources.Lang.strOrderDateDesc, Value = "DateModified;desc" }, new SelectListItem { Selected = order == "DateModified;asc" ? true : false, Text = App_GlobalResources.Lang.strOrderDateAsc, Value = "DateModified;asc" } }); List <C_Catalog> lst_parent = new List <C_Catalog>(); List <C_Catalog> lst_parent_all = new List <C_Catalog>(); if (cate == null || (cate.CategoryName != App_GlobalResources.Lang.mnuRecruitment && cate.CategoryName != App_GlobalResources.Lang.mnuBeautyTips)) { lst_parent = cateModels.GetbyParentID(0, cate_type, lang).Where(p => p.CategoryName != App_GlobalResources.Lang.mnuRecruitment && p.CategoryName != App_GlobalResources.Lang.mnuBeautyTips).ToList(); foreach (var it in lst_parent) { lst_parent_all.Add(it); var lst_child = cateModels.GetbyParentID(it.CatalogID, cate_type, lang).Where(p => p.Show == true).ToList(); foreach (var child in lst_child) { lst_parent_all.Add(child); } } } var posts_view = new ViewModels.Page_posts_view(); posts_view.List_parent_category = lst_parent; posts_view.List_parent_all = lst_parent_all; posts_view.List_page_size = this.GetSizePagingPublic(page_size ?? int.Parse(Util.GetConfigValue("NumberPageSizeNews", "8"))); posts_view.List_order = orderDrop; posts_view.Page_list_post = postModels.GetListPostAll(lang, cate_type, cate_id, search, tag, param, (int)page, (int)page_size, order_by, order_type, out total_record); posts_view.Total_record = total_record; if (total_record == 0 && search != string.Empty && !string.IsNullOrEmpty(search)) { posts_view.Text_search_result = App_GlobalResources.Lang.strSearchResult; } posts_view.Order = order; posts_view.Page_size = page_size ?? int.Parse(Util.GetConfigValue("NumberPageSizeNews", "4")); posts_view.Style_list = style_list_show; posts_view.Cate_type = cate_type; posts_view.Cate_id = cate_id ?? 0; if (cate != null && (cate.CategoryName == App_GlobalResources.Lang.mnuBeautyTips || cate.CategoryName == App_GlobalResources.Lang.mnuRecruitment)) { posts_view.Cate_name = cate.CategoryName; } else { posts_view.Cate_name = string.Empty; } posts_view.Link = link_text; posts_view.Lang = lang; posts_view.Tag = tag; posts_view.Text_search = search; posts_view.Param = param; posts_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); posts_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); return(this.PartialView("../control/post_list_all", posts_view)); }
/// <summary> /// Posts the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="cate_id">The cate identifier.</param> /// <param name="cate_type">Type of the cate.</param> /// <returns>Posts the specified</returns> public ActionResult Post(int?id, int?cate_id, string cate_type) { /////post detail PostModels postModels = new PostModels(); id = RouteData.Values["id"] != null?Convert.ToInt16(RouteData.Values["id"].ToString()) : 0; var link = RouteData.Values["Link"] != null ? RouteData.Values["Link"].ToString() : string.Empty; cate_id = string.IsNullOrEmpty(Request.QueryString["cate_id"]) ? 0 : Convert.ToInt16(Request.QueryString["cate_id"].ToString()); if (string.IsNullOrEmpty(cate_type)) { cate_type = CommonGlobal.CateNews; } if (id == 0) { return(this.HttpNotFound()); } else { postModels.ClearCache(CommonGlobal.Post + string.Empty + id); C_Post obj = postModels.GetbyID((int)id); if (obj.PostID == 0) { return(this.HttpNotFound()); } ViewBag.Title = obj.Title + " | " + GeneralModels.GetContent(CommonGlobal.PageName, this.Lang); ////breadcrumbs string strbreadcrumbs = string.Empty; CatalogModels catalogModel = new CatalogModels(); C_Catalog cateItem = new C_Catalog(); if (cate_id == 0) { if (obj.CatelogID != null && obj.CatelogID != 0) { cate_id = obj.CatelogID; } } cateItem = catalogModel.GetbyID((int)cate_id); strbreadcrumbs = string.Format("<li><a href=\"" + Url.RouteUrl((cate_type != CommonGlobal.CateService ? "_post_only" : "_service_only"), new { controller = "news", action = "posts" }) + "\">" + (cate_type != CommonGlobal.CateService ? App_GlobalResources.Lang.mnuNews : App_GlobalResources.Lang.mnuService) + "</a></li>"); if (cateItem != null) { strbreadcrumbs += string.Format("<li><a href=\"" + Url.RouteUrl(cate_type == Web.Models.CommonGlobal.CateService ? "_service" : "_post", new { controller = "news", action = "posts", id = cate_id, Link = cateItem.Link != null ? cateItem.Link : string.Empty, cate_type = cate_type }) + "\">" + cateItem.CategoryName + "</a></li>"); ViewBag.cate_name = cateItem.CategoryName; } strbreadcrumbs += string.Format("<li>" + obj.Title + "</li>"); ViewBag.str_breadcrumbs = strbreadcrumbs; ViewBag.back_link = Url.RouteUrl(cate_type == CommonGlobal.CateService ? "_service" : "_post", new { controller = "news", action = "posts", id = cate_id, Link = cateItem.Link, cate_type = cate_type }); ViewBag.heading = obj.Title; this.AddMeta(CommonGlobal.Keyword, obj.Title); this.AddMeta(CommonGlobal.Description, this.ClearHtml(HttpUtility.HtmlDecode(obj.Summary))); ViewBag.id = id; ViewBag.cate_id = cate_id; ViewBag.cate_type = cate_type; ////// Add post cookies HttpCookie mycookie = HttpContext.Request.Cookies["listPostView"]; ArrayList arrListView = new ArrayList(); ////// Lấy danh sách post đã xem từ cookies if (mycookie != null) { var arr = mycookie.Value.Split(','); for (int j = 0; j < arr.Count(); j++) { arrListView.Add(arr[j]); } } else { arrListView = new ArrayList(); } if (obj.PostID != 0) { if (!Util.CheckExistInArray(obj.PostID.ToString(), arrListView)) { arrListView.Add(obj.PostID.ToString()); } ////// Lưu danh sách xuống cookies string[] arrLst = (string[])arrListView.ToArray(typeof(string)); if (mycookie != null) { HttpContext.Response.Cookies.Remove("listPostView"); mycookie.Expires = DateTime.Now.AddMonths(-6); mycookie.Value = null; HttpContext.Response.SetCookie(mycookie); } HttpCookie cookie_new = new HttpCookie("listPostView"); cookie_new.Value = string.Join(",", arrLst); cookie_new.Expires = DateTime.Now.AddMonths(6); HttpContext.Response.Cookies.Add(cookie_new); } return(this.PartialView("../page/post")); } }
public ActionResult Change_post(FormCollection collection, HttpPostedFileBase file_image) { CatalogModels cateModels = new CatalogModels(); PostModels postModel = new PostModels(); C_Post objPost = new C_Post(); StringBuilder sb = new StringBuilder(); int rt = 0; bool is_valid = true; int level = 0; List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var post_view = new Web.Areas.Admin.ViewModels.Post_view(); this.TryUpdateModel(post_view); if (post_view.PostID > 0) { objPost = postModel.GetbyID(post_view.PostID); } ////validation server if (string.IsNullOrEmpty(post_view.PostName)) { is_valid = false; post_view.Message = "Bạn cần nhập tên danh mục"; } ////validation server if (post_view.Parent == 0) { is_valid = false; post_view.Message = "Bạn cần lựa chọn danh mục"; } ////action ////post_view.act = "change_post"; ////post_view.ctrl = "adminPost"; post_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); post_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); if (post_view.PostID != 0 && post_view.Type_act == CommonGlobal.Edit) { ////Link tab sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = post_view.Type, page = "1" }) + "\"><span><span>Danh sách tin tức</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Cập nhật</span></span></a></li>"); ////list parent cateModels.List_catalog_parent(0, level, objPost.CatelogID ?? 0, post_view.Type, objPost.Lang, ref list_select_catalog); post_view.List_category = list_select_catalog; ////list language post_view.List_language = this.List_select_language(objPost.Lang); } else { ////Link tab sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = post_view.Type, page = "1" }) + "\"><span><span>Danh sách tin tức</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>"); ////list parent cateModels.List_catalog_parent(0, level, 0, post_view.Type, post_view.Lang, ref list_select_catalog); post_view.List_category = list_select_catalog; ////list language post_view.List_language = this.List_select_language(post_view.Lang); } post_view.Html_link_tab = sb.ToString(); if (!is_valid) { return(this.PartialView("../control/change_post", post_view)); } ////Post info objPost.CatelogID = post_view.Parent; objPost.PostName = post_view.PostName; var imgPathTemp = "images/newspost/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/"; var name_time = DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + DateTime.Now.Hour + DateTime.Now.Minute + string.Empty; if (file_image != null && file_image.ContentLength > 0 && CommonGlobal.IsImage(file_image) == true) { string image_small = imgPathTemp + "sc_small_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(file_image.FileName); string image_lager = imgPathTemp + "sc_full_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(file_image.FileName); ////save image and delete old file this.Savephoto(objPost.ImagePath, file_image, imgPathTemp, image_small, image_lager); ////set image thumb to link catalog objPost.ImagePath = "/" + image_small; post_view.ImagePath = "/" + image_small; } else if (string.IsNullOrEmpty(objPost.ImagePath)) { objPost.ImagePath = "0"; } else { objPost.ImagePath = post_view.ImagePath; } objPost.Link = CommonGlobal.CompleteLink(post_view.PostName); objPost.Summary = post_view.Summary; objPost.PostContent = post_view.PostContent; objPost.DateModified = DateTime.Now; objPost.IsHot = post_view.IsHot; if (objPost.IsHot == true) { post_view.IsHot = true; post_view.Is_short_text = "checked='checked'"; } else { post_view.IsHot = false; post_view.Is_short_text = string.Empty; } objPost.Approve = post_view.Approve; if (objPost.Approve == true) { post_view.Approve = true; post_view.Show_text = "checked='checked'"; } else { post_view.Approve = false; post_view.Show_text = string.Empty; } objPost.Lang = post_view.Lang; objPost.Title = post_view.Title; objPost.Keyword = post_view.Keyword; objPost.Description = post_view.Description; objPost.OrderDisplay = post_view.OrderDisplay; if (post_view.PostID != 0 && post_view.Type_act == CommonGlobal.Edit) { objPost.CreateDate = post_view.CreateDate; rt = postModel.Edit(objPost); } else { objPost.CreateDate = DateTime.Now; rt = postModel.Add(objPost); } if (rt > 0) { post_view.Message = "Cập nhật thành công!"; post_view.PostID = rt; post_view.Type_act = CommonGlobal.Edit; } else { post_view.Message = "Cập nhật không thành công!"; } return(this.PartialView("../control/change_post", post_view)); }
public ActionResult List_post(int?parent, int?cate_id, int?post_id, string type, string act, string ctrl, string type_act, string lang, string search, int?page, int?page_size, string order_by, string order_type) { CatalogModels cataModel = new CatalogModels(); PostModels postModel = new PostModels(); C_Post post = new C_Post(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var list_post_view = new Web.Areas.Admin.ViewModels.List_post_view(); StringBuilder sb = new StringBuilder(); int total_record = 0; int level = 0; if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateNews; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "list_post"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminPost"; } if (page == null || page == 0) { page = Request.QueryString["page"] != null?Convert.ToInt32(Request.QueryString["page"].ToString()) : 1; } if (parent == null) { parent = Request.QueryString["parent"] != null?Convert.ToInt32(Request.QueryString["parent"].ToString()) : 0; } if (string.IsNullOrEmpty(lang)) { lang = LanguageModels.ActiveLanguage().LangCultureName; } if (page_size == null) { page_size = int.Parse(Util.GetConfigValue("NumberPageSizeAdmin", "30")); } list_post_view.Page = (int)page; list_post_view.Page_size = (int)page_size; list_post_view.Cate_type = CommonGlobal.GetCatalogTypeName(type); ////list category cataModel.List_catalog_parent(0, level, (int)parent, type, lang, ref list_select_catalog); list_post_view.List_parent = list_select_catalog; ////list language list_post_view.List_language = this.List_select_language(lang); ////tab sb.Append("<li class=\"active\"><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = type, page = "1", parent = parent, lang = lang }) + "\"><span><span>Danh mục " + CommonGlobal.GetCatalogTypeName(type) + "</span></span></a></li>"); sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "change_post", ctrl = "adminPost", type = type, type_act = "add", parent = parent, lang = lang }) + "\"><span><span>Thêm bài viết</span></span></a></li>"); list_post_view.Html_link_tab = sb.ToString(); if (post_id != null && post_id != 0 && type_act != null && type_act == CommonGlobal.Delete) { ////check permission delete if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, act, ctrl, type_act, type)) { post = postModel.GetbyID((int)post_id); if (post != null) { ////delete old image if (!string.IsNullOrEmpty(post.ImagePath)) { string strImg = post.ImagePath; strImg = "~" + strImg; string fileDelete = Server.MapPath(strImg); if (System.IO.File.Exists(fileDelete)) { System.IO.File.Delete(fileDelete); } string fileDelete2 = Server.MapPath(strImg.Replace("sc_small_", "sc_full_")); if (System.IO.File.Exists(fileDelete2)) { System.IO.File.Delete(fileDelete2); } } ////delete post bool rt = postModel.Delete((int)post_id); if (rt) { list_post_view.Message = "Bạn đã xóa bài viết: " + post_id; } else { list_post_view.Message = "Xóa không thành công"; } } else { list_post_view.Message = "Không tìm thấy bài viết : " + post_id; } } else { list_post_view.Message = " Bạn không có quyền thực thi hành động xóa."; } } ////list post list_post_view.List_page_size = this.GetSizePagingPublic((int)page_size); list_post_view.Page_list_post = postModel.GetListPostAll(lang, type, (int)parent, search, (int)page, (int)page_size, order_by, order_type, out total_record); list_post_view.Total_record = total_record; list_post_view.Search = search; list_post_view.Type_act = type_act; list_post_view.Type = type; ////action list_post_view.Act = act; list_post_view.Ctrl = ctrl; list_post_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); list_post_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); ////end action return(this.PartialView("../control/list_post", list_post_view)); }
public ActionResult Change_post(int?post_id, string type, string act, string ctrl, string type_act, string lang) { CatalogModels cateModels = new CatalogModels(); PostModels postModel = new PostModels(); C_Catalog cate = new C_Catalog(); C_Post objPost = new C_Post(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var post_view = new Web.Areas.Admin.ViewModels.Post_view(); StringBuilder sb = new StringBuilder(); int level = 0; if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateNews; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "change_post"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminPost"; } if (post_id == null) { post_id = RouteData.Values["id"] != null?Convert.ToInt32(RouteData.Values["id"].ToString()) : 0; } if (string.IsNullOrEmpty(lang)) { lang = LanguageModels.ActiveLanguage().LangCultureName; } if (string.IsNullOrEmpty(type_act)) { type_act = Request.QueryString["type_act"] != null ? Request.QueryString["type_act"].ToString() : CommonGlobal.Add; if (post_id == 0) { type_act = CommonGlobal.Add; } else { type_act = CommonGlobal.Edit; } } if (type_act == CommonGlobal.Edit) { objPost = postModel.GetbyID((int)post_id); post_view.PostID = objPost.PostID; post_view.PostName = objPost.PostName; post_view.PostContent = objPost.PostContent; post_view.ImagePath = objPost.ImagePath; post_view.Title = objPost.Title; post_view.Keyword = objPost.Keyword; post_view.Description = objPost.Description; post_view.Summary = objPost.Summary; post_view.Lang = objPost.Lang; post_view.CatalogID = (int)objPost.CatelogID; post_view.OrderDisplay = (int)objPost.OrderDisplay; post_view.Parent = (int)objPost.CatelogID; post_view.CreateDate = objPost.CreateDate ?? DateTime.Now; if ((objPost.IsHot ?? false) == true) { post_view.IsHot = true; post_view.Is_short_text = "checked='checked'"; } else { post_view.IsHot = false; post_view.Is_short_text = string.Empty; } if ((objPost.Approve ?? false) == true) { post_view.Approve = true; post_view.Show_text = "checked='checked'"; } else { post_view.Approve = false; post_view.Show_text = string.Empty; } cateModels.List_catalog_parent(0, level, (int)objPost.CatelogID, type, cate.Lang ?? objPost.Lang, ref list_select_catalog); ////Link tab sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = type, page = "1", lang = objPost.Lang }) + "\"><span><span>Danh sách tin tức</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Cập nhật</span></span></a></li>"); post_view.List_language = this.List_select_language(cate.Lang ?? objPost.Lang); } else { ////Link tab sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_post", ctrl = "adminPost", type = type, page = "1", lang = lang }) + "\"><span><span>Danh sách tin tức</span></span></a></li>"); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>"); cateModels.List_catalog_parent(0, level, 0, type, lang, ref list_select_catalog); post_view.List_language = this.List_select_language(lang); } post_view.List_category = list_select_catalog; post_view.Type = type; post_view.Type_act = type_act; post_view.Html_link_tab = sb.ToString(); ////action post_view.Act = act; post_view.Ctrl = ctrl; post_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); post_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); ////end action return(this.PartialView("../control/change_post", post_view)); }