public HttpResponseMessage PostMark([FromBody] CommentParams estimate) { using (SqlConnection connection = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBCS"].ConnectionString)) { string cmdString = "INSERT INTO Estimates VALUES(@AppId, @Mark, @Comment);"; SqlCommand cmd = new SqlCommand(cmdString, connection); cmd.Parameters.AddWithValue("@AppId", estimate.ApplicationId); cmd.Parameters.AddWithValue("@Mark", estimate.Mark); cmd.Parameters.AddWithValue("@Comment", estimate.Comment); try { connection.Open(); cmd.ExecuteNonQuery(); return(Request.CreateResponse(HttpStatusCode.OK, "OK")); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } } }
public ActionResult GetCommentInfo() { int pageIndex; int pageSize; if (!int.TryParse(Request["page"], out pageIndex)) { pageIndex = 1; } if (!int.TryParse(Request["rows"], out pageSize)) { pageSize = 5; } string commentmail = Request["SearchCommentMail"]; string commenttitle = Request["SearchCommentTitle"]; int totalCount = 0; CommentParams commentparams = new CommentParams() { Mail = commentmail, Title = commenttitle, PageIndex = pageIndex, PageSize = pageSize, TotalCount = totalCount }; //var userinfo = userbll.LoadPageEntities<int>(pageIndex, pageSize, out totalCount, c => true, c => c.Id, true); var commentinfo = commentbll.LoadSearchParams(commentparams); var rows = from u in commentinfo select new { Id = u.Id, Mail = u.Users.Mail, Title = u.Books.Title, Msg = u.Msg, RegTime = u.RegTime }; return(Json(new { total = commentparams.TotalCount, rows = rows }, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> GetComments(int ticketId, [FromQuery] CommentParams commentParams) { var commentsFromRepo = await _repo.GetComments(ticketId, commentParams); var comments = _mapper.Map <IEnumerable <CommentsToReturn> >(commentsFromRepo); return(Ok(new { comments, commentParams.Length })); }
public async Task <PagedList <Comment> > GetCommentsForAlbum(CommentParams commentParams) { var comments = this.context.Comments .Include(u => u.Commenter).ThenInclude(p => p.Photo) .AsQueryable() .Where(a => a.AlbumId == commentParams.AlbumId); comments = comments.OrderByDescending(d => d.CommentSent); return(await PagedList <Comment> .CreateAsync(comments, commentParams.PageNumber, commentParams.PageSize)); }
public async Task <PagedList <Comment> > GetCommentsForUser(CommentParams commentParams) { var comments = _context.Comments.Include(u => u.Sender).ThenInclude(p => p.Photos).Include(u => u.Recipient).AsQueryable(); comments = comments.Where(u => u.RecipientId == commentParams.blogId && u.IsDeletedByRecipient == false); comments = comments.OrderByDescending(d => d.SendDate); return(await PagedList <Comment> .CrateAsync(comments, commentParams.PageNumber, commentParams.PageSize)); }
public async Task <IEnumerable <Comment> > GetComments(int ticketId, CommentParams commentParams) { var comments = _context.Comments.Where(c => c.Ticket.Id == ticketId && c.IsDeleted == false) .Include(c => c.Commenter) .AsQueryable(); int length = comments.Count(); if (!string.IsNullOrEmpty(commentParams.Filter)) { comments = comments.Where(c => c.Content.Contains(commentParams.Filter)); } if (!string.IsNullOrEmpty(commentParams.OrderBy)) { switch (commentParams.OrderBy) { case "commenterasc": comments = comments.OrderBy(c => c.Commenter); break; case "commenterdesc": comments = comments.OrderByDescending(c => c.Commenter); break; case "contentasc": comments = comments.OrderBy(c => c.Content); break; case "contentdesc": comments = comments.OrderByDescending(c => c.Content); break; case "createdasc": comments = comments.OrderBy(c => c.Created); break; case "createddesc": comments = comments.OrderByDescending(c => c.Created); break; default: comments = comments.OrderBy(c => c.Created); break; } } comments = comments.Skip(commentParams.pageIndex * commentParams.PageSize).Take(commentParams.PageSize); commentParams.Length = length; return(await comments.ToListAsync()); }
public async Task <IActionResult> GetComments(int gameId, [FromQuery] CommentParams commentParams) { if (await _repo.GetGame(gameId) == null) { return(NotFound()); } var comments = await _repo.GetComments(gameId, commentParams); Response.AddPagination(comments.CurrentPage, comments.PageSize, comments.TotalCount, comments.TotalPages); return(Ok(comments)); }
public async Task <IActionResult> GetCommentsToBlog([FromQuery] CommentParams commentParams) { //if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) //{ // return Unauthorized(); //} var commentsFromRepo = await _repo.GetCommentsForUser(commentParams); var comments = _mapper.Map <IEnumerable <CommentToReturnDto> >(commentsFromRepo); Response.AddPagination(commentsFromRepo.CurrentPage, commentsFromRepo.PageSize, commentsFromRepo.TotalCount, commentsFromRepo.TotalPages); return(Ok(comments)); }
public async Task <PagedList <CommentDto> > GetComments(int gameId, CommentParams commentParams) { var commentList = (from comments in _context.Comments join users in _context.Users on comments.UserId equals users.Id where comments.GameId == gameId orderby comments.Created descending select new CommentDto { Id = comments.Id, GameId = comments.GameId, Content = comments.Content, Created = comments.Created, UserId = comments.UserId, UserName = users.UserName }); return(await PagedList <CommentDto> .CreateAsync(commentList, commentParams.PageNumber, commentParams.PageSize)); }
public async Task <PagedList <CommentModel> > GetAllCommentsAsync(int trainingPlanId, CommentParams commentParams) { var comments = _dataContext.CommentModel .Where(c => c.TrainingPlanId == trainingPlanId) .OrderByDescending(c => c.VoteCounter); if (!string.IsNullOrEmpty(commentParams.OrderBy)) { switch (commentParams.OrderBy) { case "Newest": comments = comments.OrderByDescending(c => c.DateOfCreated); break; case "Oldest": comments = comments.OrderBy(c => c.DateOfCreated); break; default: comments = comments.OrderByDescending(c => c.VoteCounter); break; } } return(await PagedList <CommentModel> .CreateListAsync(comments, commentParams.PageSize, commentParams.PageNumber)); }
public async Task <IActionResult> GetCommentsForTrainingPlanAsync(int trainingPlanId, [FromQuery] CommentParams commentParams) { var commentsToList = await _unitOfWork.Comments.GetAllCommentsAsync(trainingPlanId, commentParams); if (commentsToList == null) { return(BadRequest("Error: Comments cannot be found!")); } var commentsToReturn = _mapper.Map <IEnumerable <CommentForReturnDTO> >(commentsToList); Response.AddPagination(commentsToList.CurrentPage, commentsToList.PageSize, commentsToList.TotalCount, commentsToList.TotalPages); return(Ok(commentsToReturn)); }
public async Task <IActionResult> GetCommentsForAlbum(int userId, string albumId, [FromQuery] CommentParams commentParams) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } commentParams.AlbumId = albumId; var commentsFromRepo = await this.repo.GetCommentsForAlbum(commentParams); var comments = this.mapper.Map <IEnumerable <CommentToReturnDto> >(commentsFromRepo); Response.AddPagination(commentsFromRepo.CurrentPage, commentsFromRepo.PageSize, commentsFromRepo.TotalCount, commentsFromRepo.TotalPages); return(Ok(comments)); }