public ActionResult Details(int id, FormCollection collection) { try { //TODO: Use transaction domain.Post objCreate = new domain.Post(); objCreate.CreatedDate = DateTime.Now; objCreate.Title = "Answer"; objCreate.Body = collection.Get("answer"); objCreate.User = this.appUser.GetById(int.Parse(collection.Get("User.Id"))); objCreate.TypeOfPost = domain.TypeOfPost.Answer; appPost.Add(objCreate); domain.Post obj = new domain.Post(); obj = appPost.GetById(id); obj.UpdatedDate = DateTime.Now; appAnswerPost.Add(new domain.AnswerPost { CreatedDate = DateTime.Now, Answer = objCreate, MainPost = obj }); obj.AnswersPost.Add(new domain.AnswerPost { CreatedDate = DateTime.Now, Answer = objCreate, MainPost = obj }); return(View(new presentation.Post(obj))); } catch (Exception err) { return(View("index")); } }
// GET: Post/Delete/5 public ActionResult Delete(int id) { domain.Post obj = new domain.Post(); obj = appPost.GetById(id); appPost.Remove(obj); return(RedirectToAction("Index")); }
public Post(domain.Post post, bool withoutAnswer = false) { this.Id = post.Id; this.CreatedDate = post.CreatedDate; this.UpdatedDate = post.UpdatedDate; this.AnswersPost = new List <AnswerPost>(); if (!withoutAnswer && post.AnswersPost != null && post.AnswersPost.Count > 0) { this.AnswersPost.AddRange(AnswerPost.ParseListDomainToPresentation(post.AnswersPost)); } this.Body = post.Body; this.Title = post.Title; this.User = new User(post.User); }
public Post(domain.Post post, object userID, bool overrideUser = false) : this(post) { if (userID != null) { if (overrideUser) { this.User = new User { Id = int.Parse(userID.ToString()) } } ; this.CanEdit = post.CanEditPost(int.Parse(userID.ToString())); } }
public ActionResult Edit(int id, FormCollection collection) { try { domain.Post obj = new domain.Post(); obj = appPost.GetById(id); obj.UpdatedDate = DateTime.Now; obj.Title = collection.Get("Title"); obj.Body = collection.Get("Body"); appPost.Update(obj); return(RedirectToAction("Index")); } catch (Exception err) { return(View()); } }
public ActionResult Create(FormCollection collection) { try { domain.Post obj = new domain.Post(); obj.CreatedDate = DateTime.Now; obj.Title = collection.Get("Title"); obj.Body = collection.Get("Body"); obj.User = new domain.User { Id = int.Parse(collection.Get("User.Id")) }; obj.TypeOfPost = domain.TypeOfPost.Main; appPost.Add(obj); return(RedirectToAction("Index")); } catch { return(View()); } }