Example #1
0
 public ActionResult Create(PostView NewPostView)
 {
     Post pNewPost = new Post();
     try
     {
         // TODO: Add insert logic here
         pNewPost.Avatar = NewPostView.Avatar;
         pNewPost.AccountID = account.Id;
         pNewPost.PostContent = NewPostView.pContent;
         pNewPost.TopicID = new TopicModel().GetIdByName(NewPostView.pNameTopic);
         pNewPost.Like = 0;
         pNewPost.Dislike = 0;
         pNewPost.Descrip = NewPostView.pDescrip;
         pNewPost.PostDate = DateTime.Now;
         pNewPost.IsActive = true;
         pNewPost.LangId = 0;
         var check = new PostModel().Create(pNewPost);
         if(check==true)
         {
             return RedirectToAction("Index");
         }
         return View(NewPostView);
     }
     catch
     {
         return View(NewPostView);
     }
 }
Example #2
0
        public bool Edit(int pId,Post pNewPost)
        {
            try
            {
                var Object = _db.Posts.Find(pId);
                Object.AccountID = pNewPost.AccountID;
                Object.Descrip = pNewPost.Descrip;
                Object.UpFile = pNewPost.UpFile;
                Object.PostDate = pNewPost.PostDate;
                Object.PostContent = pNewPost.PostContent;
                Object.Like = pNewPost.Like;
                Object.Dislike = pNewPost.Dislike;
                Object.IsActive = pNewPost.IsActive;
                Object.LangId = pNewPost.LangId;
                Object.Permission = pNewPost.Permission;
                Object.ParentId = pNewPost.ParentId;
                _db.SaveChanges();
                return true;
            }
            catch
            {
                return false;

            }
        }
Example #3
0
 public bool Create(Post pNewPost)
 {
     try
     {
         _db.Posts.Add(pNewPost);
         _db.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
Example #4
0
        public bool Edit(int pId,Post pNewPost)
        {
            try
            {
                var Object = _db.Posts.Find(pId);
                Object.TopicID = pNewPost.TopicID;
                Object.Descrip = pNewPost.Descrip;
                Object.UpFile = pNewPost.UpFile;
                Object.PostContent = pNewPost.PostContent;
                Object.Permission = pNewPost.Permission;
                Object.ParentId = pNewPost.ParentId;
                Object.Avatar = pNewPost.Avatar;
                _db.SaveChanges();
                return true;
            }
            catch
            {
                return false;

            }
        }
Example #5
0
 public ActionResult NewPost(PostView pNewPost)
 {
     try {
         HttpPostedFileBase file = HttpContext.Request.Files["pImage"];
         string a = "/Image/" + file.FileName;
         string b = Server.MapPath(a);
         file.SaveAs(b);
         var Object = new Post();
         Object.Descrip = pNewPost.pDescrip;
         Object.PostContent = pNewPost.pContent;
         Object.TopicID = new TopicModel().GetIdByName(pNewPost.pNameTopic);
         Object.AccountID = IdAccount;
         Object.PostDate = DateTime.Now;
         Object.Image = a;
         Object.Like = 0;
         Object.Dislike = 0;
         Object.IsActive = true;
         Object.LangId = 0;
         Object.Permission = 1;
         Object.ParentId = 0;
         bool check = new PostModel().Create(Object);
         var Result = new PostModel().GetNewPostByAccountId(IdAccount).ID;
         if (check)
         {
             return RedirectToAction("Post", "Home", new { id = Result });
         }
         else
         {
             ViewBag.ListTopic = new TopicModel().GetListTopic();
             return View();
         }
     }
     catch
     {
         ViewBag.ListTopic = new TopicModel().GetListTopic();
         return View();
     }
 }
Example #6
0
        public ActionResult NewPost(PostView NewPostView)
        {
            if(account==null)
                return RedirectToAction("Index","Error");
            Post pNewPost = new Post();
            try
            {
                // TODO: Add insert logic here
                pNewPost.Avatar = NewPostView.Avatar;
                pNewPost.AccountID = account.Id;
                pNewPost.PostContent = NewPostView.pContent;
                pNewPost.TopicID = new TopicModel().GetIdByName(NewPostView.pNameTopic);
                pNewPost.Like = 0;
                pNewPost.Dislike = 0;
                pNewPost.Descrip = NewPostView.pDescrip;

                // string.IsNullOrEmpty(value)
                if (NewPostView.pDescrip == "" || NewPostView.Avatar == ""||NewPostView.pContent=="")
                {
                    ViewBag.ListTopic = new TopicModel().GetListTopic();
                }
                pNewPost.PostDate = DateTime.Now;
                pNewPost.IsActive = true;
                pNewPost.LangId = 0;
                var check = new PostModel().Create(pNewPost);
                if (check == true)
                {
                    return RedirectToAction("Index");
                }
                ViewBag.ListTopic = new TopicModel().GetListTopic();
                return View(NewPostView);
            }
            catch
            {
                ViewBag.ListTopic = new TopicModel().GetListTopic();
                return View(NewPostView);
            }
        }
Example #7
0
 public ActionResult Edit(int id, PostView NewPostView)
 {
     Post pNewPost = new Post();
     try
     {
         // TODO: Add insert logic here
         pNewPost.Avatar = NewPostView.Avatar;
         pNewPost.PostContent = NewPostView.pContent;
         pNewPost.TopicID = new TopicModel().GetIdByName(NewPostView.pNameTopic);
         pNewPost.Descrip = NewPostView.pDescrip;
         pNewPost.IsActive = true;
         var check = new PostModel().Edit(id, pNewPost);
         if (check)
             return RedirectToAction("Index");
         else
             return View(NewPostView);
     }
     catch
     {
         return View(NewPostView);
     }
 }