示例#1
0
        public ActionResult Index(S_Post spost)
        {
            string msg = "";

            if (ModelState.IsValid)

            {
                if (Session["ID"] != null)
                {
                    var id = Session["ID"];
                    try
                    {
                        List <object> obj = new List <Object>();
                        obj.Add(spost.PostTime);
                        obj.Add(spost.PostContent);

                        obj.Add(spost.Post_like);
                        obj.Add(spost.S_userID);
                        obj.Add(spost.Postimgid);

                        object[] dataarray = obj.ToArray();
                        int      output    = db.Database.ExecuteSqlCommand("insert into S_Post(PostTime,PostContent,Post_like,S_userID,Postimgid)values(@p0,@p1,@p2,@p3,@p4)", dataarray);
                        if (output > 0)
                        {
                            ViewBag.Message = "Added";
                        }
                        //return RedirectToAction("EmartInWall");
                        //return Convert.ToString(output);
                        msg = "Successfully Saved";
                    }
                    catch (Exception e)
                    {
                        msg = e.Message;
                    }
                }

                else
                {
                    msg = "Please Provide the content";
                }
            }
            if (Request.IsAjaxRequest())
            {
                return(new JsonResult {
                    Data = msg, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            else
            {
                ViewBag.Message = msg;
                return(View(spost));
            }
        }
示例#2
0
        public JsonResult UploadPostImage(S_Post post)

        {
            int ImageID = 0;
            var file    = post.PostImage;

            byte[] imagbyte = null;

            if (file != null)
            {
                file.SaveAs(Server.MapPath("/uploadpostimage/" + file.FileName));

                BinaryReader reader = new BinaryReader(file.InputStream);
                imagbyte = reader.ReadBytes(file.ContentLength);
                UserPostImages img = new UserPostImages();
                img.ImageName      = file.FileName;
                img.ImageByte      = imagbyte;
                img.ImagePath      = "/uploadpostimage/" + file.FileName;
                img.ImageisDeleted = false;
                db.UserPostImages.Add(img);
                db.SaveChanges();

                List <S_frns> frnsList = db.S_frnss.SqlQuery("select * from S_frns where s_frnID=@p0", post.S_userID).ToList();
                for (var i = 0; i < frnsList.Count; i++)
                {
                    int err = db.Database.ExecuteSqlCommand("insert into Notifications (userid,postid,status) values(@p0,@p1,@p2)", frnsList[i].S_userID, post.postID, 1);
                }


                ImageID        = img.ImageID;
                post.Postimgid = ImageID;
                S_Post        p   = new S_Post();
                List <object> obj = new List <Object>();
                obj.Add(post.PostTime);
                obj.Add(post.PostContent);

                obj.Add(post.Post_like);
                obj.Add(post.S_userID);
                obj.Add(post.Postimgid);

                object[] dataarray = obj.ToArray();
                int      output    = db.Database.ExecuteSqlCommand("insert into S_Post(PostTime,PostContent,Post_like,S_userID,Postimgid)values(@p0,@p1,@p2,@p3,@p4)", dataarray);
                if (output > 0)
                {
                    ViewBag.Message = "Added";
                }
            }

            return(Json(ImageID, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public ActionResult ListPossts()
        {
            if (Session["ID"] != null)
            {
                S_Post          post      = new S_Post();
                SocialViewModel a         = new SocialViewModel();
                var             id        = Session["ID"];
                var             Posttlist = db.S_Posts.SqlQuery("Select * from S_Post").ToList();
                //c = new SocialViewModel();



                return(View(Posttlist));


                //    }
            }

            return(View());
        }