Exemplo n.º 1
0
        public CommentsBEL AddComment(CommentsBEL commentBEL)
        {
            CommentsBEL CommentsDetails = new CommentsBEL();
            DataSet     ds = null;

            try
            {
                SqlParameter[] SqlParms = new SqlParameter[6];

                SqlParms[0]           = new SqlParameter("@UserId", SqlDbType.NVarChar, 50);
                SqlParms[0].Direction = ParameterDirection.Input;
                SqlParms[0].Value     = commentBEL.userId;

                SqlParms[1]           = new SqlParameter("@PostId", SqlDbType.NVarChar, 50);
                SqlParms[1].Direction = ParameterDirection.Input;
                SqlParms[1].Value     = commentBEL.postId;

                SqlParms[2]           = new SqlParameter("@Comment", SqlDbType.NVarChar, 1500);
                SqlParms[2].Direction = ParameterDirection.Input;
                SqlParms[2].Value     = commentBEL.commentText;

                SqlParms[3]           = new SqlParameter("@Avatar", SqlDbType.NVarChar, 800);
                SqlParms[3].Direction = ParameterDirection.Input;
                SqlParms[3].Value     = commentBEL.avatar;

                SqlParms[4]           = new SqlParameter("@Error", SqlDbType.NVarChar, 500);
                SqlParms[4].Direction = ParameterDirection.Output;

                SqlParms[5]           = new SqlParameter("@CommentID", SqlDbType.NVarChar, 50);
                SqlParms[5].Direction = ParameterDirection.Output;

                ds = SqlHelper.ExecuteDataset(connectionString, CommandType.StoredProcedure, "Add_NewComments", SqlParms);
                //&& Convert.ToString(SqlParms[5].Value) != "0"
                if (ds == null && ds.Tables.Count <= 0)
                {
                    CommentsDetails.userId       = "";
                    CommentsDetails.commentId    = "0";
                    CommentsDetails.ErrorMessage = Convert.ToString(SqlParms[4].Value) + " Data Not Found";
                }
                else if (Convert.ToString(SqlParms[4].Value) == string.Empty)
                {
                    CommentsDetails.postId       = ds.Tables[0].Rows[0]["Post_ID"].ToString();
                    CommentsDetails.userId       = ds.Tables[0].Rows[0]["User_Id"].ToString();
                    CommentsDetails.commentText  = ds.Tables[0].Rows[0]["Text"].ToString();
                    CommentsDetails.commentId    = ds.Tables[0].Rows[0]["Comment_id"].ToString();
                    CommentsDetails.avatar       = ds.Tables[0].Rows[0]["Avatar"].ToString();
                    CommentsDetails.likes        = "0";
                    CommentsDetails.ErrorMessage = string.Empty;

                    // ResultDTO. = Convert.ToString(SqlParms[5].Value);
                }
                else
                {
                    CommentsDetails.userId       = "";
                    CommentsDetails.commentId    = "0";
                    CommentsDetails.ErrorMessage = Convert.ToString(SqlParms[4].Value);
                }
            }
            catch (Exception ex)
            {
                CommentsDetails.userId       = "";
                CommentsDetails.commentId    = "0";
                CommentsDetails.ErrorMessage = "DataBase Error Occured : " + ex.Message;
            }

            return(CommentsDetails);
        }
Exemplo n.º 2
0
        public List <PostsBEL> GetAllPosts()
        {
            List <PostsBEL> Posts = new List <PostsBEL>();

            try
            {
                DataSet ds = null;

                SqlParameter[] SqlParms = new SqlParameter[1];

                SqlParms[0]           = new SqlParameter("@Error", SqlDbType.NVarChar, 150);
                SqlParms[0].Direction = ParameterDirection.Output;

                //SqlParms[7] = new SqlParameter("@UserId", SqlDbType.NVarChar, 20);
                //SqlParms[7].Direction = ParameterDirection.Output;



                ds = SqlHelper.ExecuteDataset(connectionString, CommandType.StoredProcedure, "Get_AllPosts", SqlParms);

                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    CommentsBEL c = new CommentsBEL();

                    /*Posts = (from DataRow Post in ds.Tables[0].Rows
                     *
                     *           select new PostsBEL
                     *           {
                     *               /* userId = Convert.ToString(parkingrow["User_id"]),
                     *                postId = Convert.ToString(parkingrow["Menu_id"]),
                     *                postDescription = Convert.ToString(parkingrow["Menu_description"]),
                     *
                     *              post.a Comments
                     *
                     *               Success = true,
                     *               ErrorMessage = "",
                     *           }
                     *              ).ToList<PostsBEL>();
                     */
                    PostsBEL           post;     // = new PostsBEL();
                    List <CommentsBEL> comments; // = new List<CommentsBEL>();
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        post                 = new PostsBEL();
                        comments             = new List <CommentsBEL>();
                        post.postId          = ds.Tables[0].Rows[i]["Post_id"].ToString();
                        post.postName        = ds.Tables[0].Rows[i]["PostName"].ToString();
                        post.postDescription = ds.Tables[0].Rows[i]["PostDescription"].ToString();
                        post.postedByUName   = ds.Tables[0].Rows[i]["postedby"].ToString();
                        post.userId          = ds.Tables[0].Rows[i]["postedByUid"].ToString();
                        post.dateCreated     = ds.Tables[0].Rows[i]["PostCreatedOn"].ToString();
                        post.avatar          = ds.Tables[0].Rows[i]["PostAvatar"].ToString();
                        post.likes           = ds.Tables[0].Rows[i]["likes"].ToString();
                        post.Success         = true;
                        //c = new CommentsBEL();
                        for (int k = i; k < ds.Tables[0].Rows.Count; k++)
                        {
                            if (post.postId == ds.Tables[0].Rows[k]["CPostId"].ToString())
                            {
                                c                  = new CommentsBEL();
                                c.commentId        = ds.Tables[0].Rows[k]["Comment_id"].ToString();
                                c.commentText      = ds.Tables[0].Rows[k]["comment"].ToString();
                                c.CommentedByUName = ds.Tables[0].Rows[k]["CommentedByName"].ToString();
                                c.userId           = ds.Tables[0].Rows[k]["commentedByUid"].ToString();
                                c.likes            = ds.Tables[0].Rows[k]["Commentlikes"].ToString();
                                c.avatar           = ds.Tables[0].Rows[k]["CommentAvatar"].ToString();
                                c.dateCreated      = ds.Tables[0].Rows[k]["CommentDate"].ToString();
                                c.postId           = ds.Tables[0].Rows[k]["CPostid"].ToString();
                                comments.Add(c);

                                i = k;
                            }
                        }
                        post.Comments = comments;
                        // i = k;
                        //po
                        Posts.Add(post);
                    }

                    return(Posts);
                }
                else
                {
                    Posts.Add(new PostsBEL()
                    {
                        Success = false, ErrorMessage = Convert.ToString(SqlParms[1].Value)
                    });
                    return(Posts);
                }
            }
            catch (Exception ex)
            {
                Posts.Add(new PostsBEL()
                {
                    Success = false, ErrorMessage = Convert.ToString(ex.Message.ToString())
                });
                return(Posts);
            }

            //  return AvailableParkings;
        }
Exemplo n.º 3
0
        public HttpResponseMessage AddComment(AddCommentViewModel vm)
        {
            var     res      = new HttpResponseMessage();
            JObject jContent = new JObject();
            Random  ran      = new Random();

            if (vm != null)
            {
                // vm.Password = Secure.Encrypt(vm.Password);// Secure.Encrypt("TWuser@" + Convert.ToString(ran.Next(1000, 9999)));
                //  vm.ConfirmPassword = Secure.Encrypt(vm.Password);
                if (ModelState.IsValid)
                {
                    try
                    {
                        CommentsBEL objCommentBEL = new CommentsBEL();

                        objCommentBEL.userId      = vm.userId;
                        objCommentBEL.postId      = vm.postId;
                        objCommentBEL.commentText = vm.commentText;
                        objCommentBEL.avatar      = vm.Avatar;
                        // objPostBEL. = vm.Mobile;

                        UserDetailsDAL objUserDAL = new UserDetailsDAL();
                        CommentsBEL    ulvm       = new CommentsBEL(objUserDAL.AddComment(objCommentBEL));

                        if (ulvm.commentId != "0")
                        {
                            res.StatusCode = HttpStatusCode.Created;
                            jContent       = new JObject(
                                new JProperty("result",
                                              new JObject(
                                                  new JProperty("Success", true),
                                                  new JProperty("Message", "Post added successfully"),
                                                  new JProperty("CommentId", ulvm.commentId))));
                        }
                        else
                        {
                            res.StatusCode = HttpStatusCode.BadRequest;
                            jContent       = new JObject(
                                new JProperty("result",
                                              new JObject(
                                                  new JProperty("Success", false),
                                                  new JProperty("Message", ulvm.ErrorMessage),
                                                  new JProperty("ErrorMessage", ulvm.ErrorMessage),
                                                  new JProperty("CommentId", ulvm.commentId))));
                        }
                    }
                    catch (Exception ex)
                    {
                        res.StatusCode = HttpStatusCode.BadRequest;
                        jContent       = new JObject(
                            new JProperty("result",
                                          new JObject(
                                              new JProperty("Success", false),
                                              new JProperty("Message", ex.Message),
                                              new JProperty("ErrorMessage", ex.InnerException.ToString()),
                                              new JProperty("CommentId", null))));
                    }
                }
                else
                {
                    var errorList = (from item in ModelState
                                     where item.Value.Errors.Any()
                                     select item.Value.Errors[0].ErrorMessage).ToList();
                    res.StatusCode = HttpStatusCode.BadRequest;
                    jContent       = new JObject(
                        new JProperty("result",
                                      new JObject(
                                          new JProperty("Success", false),
                                          new JProperty("Message", "Invalid Input"),
                                          new JProperty("ErrorMessage", errorList),
                                          new JProperty("CommentId", null))));
                }
            }
            res.Content = new StringContent(jContent.ToString());
            return(res);
        }