public List<Access.DataModels.Comment> GetComments(int postId) { var comments = from c in _dataContext.Posts where c.ParentId == postId select c; var result = new List<Access.DataModels.Comment>(); var querry = comments.ToList(); var userDataAccess = new UserDataAccess(); for (int i = 0; i < querry.Count(); i++) { var p = Mapper.Map<Post, Access.DataModels.Comment>(querry[i]); p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId); result.Add(p); } return result; }
public List<Access.DataModels.Post> GetNewPosts(int postType,string time) { if (postType == 0) { var posts = from p in _dataContext.Posts where p.PostTypeId != (int) Access.DataModels.PostTypes.Comment && p.IsAnonymous == false && p.LastActivityDate > Convert.ToDateTime(time) select p; var result = new List<Access.DataModels.Post>(); var querry = posts.ToList(); UserDataAccess userDataAccess = new UserDataAccess(); for (int i = 0; i < querry.Count(); i++) { var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]); p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId); result.Add(p); } return result; } else if ((_dataContext.PostTypes.Any(row => row.Id == postType) != true)) throw new InvalidPostTypeTypeXception("the given post type does not exist"); else { var posts = from p in _dataContext.Posts where p.PostTypeId == postType && p.IsAnonymous == false && p.LastActivityDate > Convert.ToDateTime(time) select p; var result = new List<Access.DataModels.Post>(); var querry = posts.ToList(); var userDataAccess = new UserDataAccess(); for (int i = 0; i < querry.Count(); i++) { var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]); p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId); result.Add(p); } return result; } }
public ActionResult GetUserPicUrl(int id) { try { var userDataAccess = new UserDataAccess(); string url = userDataAccess.GetUserPicUrl(id); return Json(new { Status = "SUCCESS", Result = url }, JsonRequestBehavior.AllowGet); } catch (Exception) { return Json(new { Status = "FAILED", Result = "" }, JsonRequestBehavior.AllowGet); } }
public Access.DataModels.Post GetPost(int postId) { var post = _dataContext.Posts.Single(p => p.Id == postId); if (post == null) { throw new InvalidPostIdXception("there esist no post with the given post id"); } else { var p = Mapper.Map<Post, Access.DataModels.Post>(post); UserDataAccess userDataAccess = new UserDataAccess(); p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId); return p; } }
//public List<Access.DataModels.Post> GetMorePosts(int postType,int startIndex,int maxAmount) //{ //} public List<Access.DataModels.Post> GetPosts(int postType,int taggedUserId,int maxAmount, bool includeAnonymous=false) { if (postType == 0) { if(includeAnonymous) { var posts = from p in _dataContext.Posts where p.PostTypeId != (int)Access.DataModels.PostTypes.Comment && p.TaggedUserId==taggedUserId orderby p.LastActivityDate descending select p; var result = new List<Access.DataModels.Post>(); var querry = posts.ToList(); var userDataAccess = new UserDataAccess(); for (int i = 0; i < Math.Min(querry.Count(), maxAmount); i++) { var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]); p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId); result.Add(p); } return result; }else { var posts = from p in _dataContext.Posts where p.PostTypeId != (int)Access.DataModels.PostTypes.Comment && p.IsAnonymous==false && p.TaggedUserId == taggedUserId orderby p.LastActivityDate descending select p; var result = new List<Access.DataModels.Post>(); var querry = posts.ToList(); var userDataAccess = new UserDataAccess(); for (int i = 0; i < Math.Min(querry.Count(), maxAmount); i++) { var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]); p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId); result.Add(p); } return result; } } else if ((_dataContext.PostTypes.Any(row => row.Id == postType) != true)) throw new InvalidPostTypeTypeXception("the given post type does not exist"); else { if(includeAnonymous) { var posts = from p in _dataContext.Posts where p.PostTypeId == postType && p.TaggedUserId == taggedUserId orderby p.LastActivityDate descending select p; var result = new List<Access.DataModels.Post>(); var querry = posts.ToList(); var userDataAccess = new UserDataAccess(); for (int i = 0; i < Math.Min(querry.Count(), maxAmount); i++) { var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]); p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId); result.Add(p); } return result; }else { var posts = from p in _dataContext.Posts where p.PostTypeId == postType && p.IsAnonymous == false && p.TaggedUserId==taggedUserId orderby p.LastActivityDate descending select p; var result = new List<Access.DataModels.Post>(); var querry = posts.ToList(); var userDataAccess = new UserDataAccess(); for (int i = 0; i < Math.Min(querry.Count(), maxAmount); i++) { var p = Mapper.Map<Post, Access.DataModels.Post>(querry[i]); p.OwnerPicUrl = userDataAccess.GetUserPicUrl((int)p.OwnerUserId); result.Add(p); } return result; } } }