コード例 #1
0
        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"));
            }
        }
コード例 #2
0
 // 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"));
 }
コード例 #3
0
ファイル: Post.cs プロジェクト: MicaelPereira/ForumStartup
 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);
 }
コード例 #4
0
ファイル: Post.cs プロジェクト: MicaelPereira/ForumStartup
 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()));
     }
 }
コード例 #5
0
        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());
            }
        }
コード例 #6
0
        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());
            }
        }