public int UpdatePostToDB(InzPost ObjPost) { string CS = DBConnect.ConnectionString(); try { using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand("spUpdatePostDetails", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@PostId", ObjPost.PostId); cmd.Parameters.AddWithValue("@Title", ObjPost.Title); cmd.Parameters.AddWithValue("@SubDescription", ObjPost.SubDescription); cmd.Parameters.AddWithValue("@Category", ObjPost.Category); cmd.Parameters.AddWithValue("@IsPublic", ObjPost.IsPublic); cmd.Parameters.AddWithValue("@Description", ObjPost.Description); cmd.Parameters.AddWithValue("@ReferenceURL", ObjPost.ReferenceURL); cmd.Parameters.AddWithValue("@ReferenceURL", ObjPost.ReferenceURL); cmd.Parameters.AddWithValue("@FileName", string.IsNullOrWhiteSpace(ObjPost.FileName) ? "" : ObjPost.FileName.ToString()); con.Open(); return((int)cmd.ExecuteScalar()); } } catch { return(0); } }
public List <InzPost> ListOthersPost(int UserId) { List <InzPost> PostList = new List <InzPost>(); SqlCommand cmd; using (SqlConnection con = new SqlConnection(DBConnect.ConnectionString())) { con.Open(); cmd = new SqlCommand("select * from Inz_post WHere PostID IN (select PostID FROM FriendSuggest Where USERID=@UserID and IsAccepted=0)", con); // cmd = new SqlCommand("select * from Inz_post WHere UserID!=@UserID and PostID NOT IN (select PostID FROM PostShared Where USERID=@UserID AND IsDeclined!=1)", con); // cmd = new SqlCommand("Select P.PostId,Title,SubDescription,Description,P.Category,P.IsApproved,P.ReferenceURL from inz_Post P JOIN PostShared S ON S.PostId=P.PostID WHERE S.IsDeclined=0 AND P.UserID=@UserID", con); cmd.Parameters.AddWithValue("@UserID", UserId); cmd.CommandType = CommandType.Text; SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { InzPost _post = new InzPost(); _post.PostId = (int)rdr["PostId"]; _post.Title = rdr["Title"].ToString(); _post.SubDescription = rdr["SubDescription"].ToString(); _post.Category = rdr["Category"].ToString(); _post.IsApproved = Convert.ToInt32(rdr["IsApproved"]); _post.ReferenceURL = rdr["ReferenceURL"].ToString(); _post.FileName = rdr["FileName"].ToString(); PostList.Add(_post); } } return(PostList); }
public int InsertPostToDB(InzPost ObjPost) { try { using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand("spInsertPostDetails", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserId", Convert.ToInt32(ObjPost.UserId)); cmd.Parameters.AddWithValue("@Title", ObjPost.Title.ToString()); cmd.Parameters.AddWithValue("@SubDescription", ObjPost.SubDescription.ToString()); cmd.Parameters.AddWithValue("@Category", ObjPost.Category.ToString()); cmd.Parameters.AddWithValue("@IsPublic", Convert.ToInt32(ObjPost.IsPublic)); cmd.Parameters.AddWithValue("@Description", ObjPost.Description.ToString()); cmd.Parameters.AddWithValue("@ReferenceURL", ObjPost.ReferenceURL.ToString()); cmd.Parameters.AddWithValue("@FileName", ObjPost.FileName.ToString()); con.Open(); return((int)cmd.ExecuteScalar()); } } catch { return(-2); } }
public ActionResult Index(FormCollection frmCollection, HttpPostedFileBase files) { InzPost _post = new InzPost { Title = frmCollection["PostTitle"].ToString(), SubDescription = frmCollection["SubDescription"].ToString(), Category = frmCollection["Category"].ToString(), Description = frmCollection["Description"], IsPublic = frmCollection["Privacy"].ToString() == "Public"?1:0, ReferenceURL = frmCollection["ReferenceURL"].ToString(), UserId = USerConfig.GetUserID(), FileName = files.FileName.ToString() }; if (files != null) { if (files.ContentLength > 0) { var fileName = Path.GetFileName(files.FileName); var path = Path.Combine(Server.MapPath("~/PostImage"), fileName); files.SaveAs(path); } } Dictionary <int, string> Response = ObjPostSericeLayer.SavePost(_post); string getResponse = ""; int GetPostIdAsReturnCode = 0; foreach (var pair in Response) { GetPostIdAsReturnCode = pair.Key; getResponse = pair.Value; } FileDataLayer objFileDataLayer = new FileDataLayer(); objFileDataLayer.SaveFile(USerConfig.GetUserID(), GetPostIdAsReturnCode); TempData["AlertMessage"] = getResponse; ViewBag.Categories = ObjPostSericeLayer.GetCategories(); if (GetPostIdAsReturnCode != -1 || GetPostIdAsReturnCode != -2) { InzPost SavedPost = new InzPost(); SavedPost.PostId = GetPostIdAsReturnCode; return(View()); } else { return(View()); } }
public IEnumerable <InzPost> GetAllSharedAndOwnPost(int UserId) { List <InzPost> PostList = new List <InzPost>(); SqlCommand cmd; using (SqlConnection con = new SqlConnection(DBConnect.ConnectionString())) { con.Open(); if (UserId == 0)//is admin { cmd = new SqlCommand("select * from inz_Post order by 1 desc", con); } else { cmd = new SqlCommand("select * from inz_Post where PostID in (select FileId from FilePartners where USERID=@UserID AND Isdeleted=0) order by 1 desc", con); cmd.Parameters.AddWithValue("@UserID", UserId); } cmd.CommandType = CommandType.Text; SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { InzPost _post = new InzPost(); _post.PostId = (int)rdr["PostId"]; _post.Title = rdr["Title"].ToString(); _post.SubDescription = rdr["SubDescription"].ToString(); _post.Description = rdr["Description"].ToString(); _post.Category = rdr["Category"].ToString(); _post.IsApproved = Convert.ToInt32(rdr["IsApproved"]); _post.ReferenceURL = rdr["ReferenceURL"].ToString(); _post.ListPost = ListOthersPost(UserId); _post.FileName = SetFile(rdr["FileName"].ToString()); PostList.Add(_post); } } else { InzPost _post = new InzPost(); _post.ListPost = ListOthersPost(UserId); _post.NoPost = true; PostList.Add(_post); } } return(PostList); }
public string UpdatePost(InzPost ObjPost) { if (ObjPostDatalayer.UpdatePostToDB(ObjPost) == 1) { return("Sucess"); } else if (ObjPostDatalayer.UpdatePostToDB(ObjPost) == -1) { return("AlreadyExists"); } else { return("Error"); } }
public ActionResult SuggestActionPost() { int PostId = Convert.ToInt32(Request.Form["PostId"]); if (PostId == 0) { PostId = Convert.ToInt32(TempData["PostId"]); } string SuggestFriend = Request.Form["Email"].ToString(); string getResponse = ObjPostSericeLayer.SuggestPost(SuggestFriend, PostId); TempData["AlertMessage"] = getResponse; InzPost SavedPost = new InzPost(); SavedPost.PostId = PostId; return(View(SavedPost)); }
public ActionResult ManagePost(FormCollection frmCollection) { InzPost _post = new InzPost(); _post.PostId = Convert.ToInt32(frmCollection["PostId"]); _post.Title = frmCollection["Title"].ToString(); _post.SubDescription = frmCollection["SubDescription"].ToString(); _post.Category = frmCollection["Category"].ToString(); _post.Description = frmCollection["Description"]; _post.IsPublic = frmCollection["Privacy"].ToString() == "Public" ? 1 : 0; _post.ReferenceURL = frmCollection["ReferenceURL"].ToString(); string getResponse = ObjPostSericeLayer.UpdatePost(_post); TempData["AlertMessage"] = getResponse; TempData["PostId"] = getResponse; List <InzPost> ListPost = new List <InzPost>(); ListPost = ObjPostSericeLayer.GetPostDetails(USerConfig.GetUserID()); return(View(ListPost.OrderBy(x => x.PostId).ToList())); }
public Dictionary <int, string> SavePost(InzPost ObjPost) { Dictionary <int, string> SavedPost; //= new Dictionary<int, string>(); int ReturnCode = ObjPostDatalayer.InsertPostToDB(ObjPost); if (ReturnCode == -1) { SavedPost = new Dictionary <int, string>(); SavedPost.Add(ReturnCode, "AlreadyExists"); return(SavedPost); } else if (ReturnCode != -1) { SavedPost = new Dictionary <int, string>(); SavedPost.Add(ReturnCode, "Sucess"); return(SavedPost); } else { SavedPost = new Dictionary <int, string>(); SavedPost.Add(ReturnCode, "Error"); return(SavedPost); } //else if (ObjPostDatalayer.InsertPostToDB(ObjPost) != -1) //{ // return "Sucess"; //} //else if (ObjPostDatalayer.InsertPostToDB(ObjPost) == 0) //{ // return "Error"; //} //else //{ // return "Error"; //} }
public IEnumerable <InzPost> GetPostDetails(int UserId) { List <InzPost> PostList = new List <InzPost>(); SqlCommand cmd; using (SqlConnection con = new SqlConnection(DBConnect.ConnectionString())) { con.Open(); if (UserId == 0)//is admin { cmd = new SqlCommand("select * from inz_Post order by 1 desc", con); } else { cmd = new SqlCommand("select * from inz_Post where UserID=@UserID order by PostId desc", con); cmd.Parameters.AddWithValue("@UserID", UserId); } cmd.CommandType = CommandType.Text; SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { InzPost _post = new InzPost(); _post.PostId = (int)rdr["PostId"]; _post.Title = rdr["Title"].ToString(); _post.SubDescription = rdr["SubDescription"].ToString(); _post.Description = rdr["Description"].ToString(); _post.Category = rdr["Category"].ToString(); _post.ReferenceURL = rdr["ReferenceURL"].ToString(); _post.path = rdr["FileName"].ToString(); PostList.Add(_post); } } return(PostList); }
public ActionResult SuggestAction() { InzPost SavedPost = new InzPost(); return(View(SavedPost)); }