public async Task <IActionResult> Create(ReviewViewModel Review) { if (ModelState.IsValid) { ReviewDto updatedReview = new ReviewDto { CustomerId = 1, /*CustomerId = customerId,*/ CustomerName = "Carter", /*CustomerName = customerName,*/ ProductId = Review.ProductId, ProductName = Review.ProductName, Timestamp = DateTime.Now, Rating = Review.Rating, ReviewText = Review.ReviewText }; try { await _reviewFacade.NewReview(updatedReview); } catch (HttpRequestException) { _logger.LogWarning("Exception Occured using Review Facade"); } return(RedirectToAction("History", "Order")); } return(View(Review)); }
public void Map_MapFromReviewDtoToReview_CorrectType() { var reviewDto = new ReviewDto(); var review = uut.Map <Review>(reviewDto); Assert.That(review, Is.TypeOf <Review>()); }
public async Task ThrowExeptionWhenUserNoHAveBookForReturnReturnBook_Test() { var isbn = "TestIsbn"; var username = "******"; var reviewDto = new ReviewDto(); var options = TestUtilities.GetOptions(nameof(ThrowExeptionWhenUserNoHAveBookForReturnReturnBook_Test)); using (var actContext = new LibrarySystemContext(options)) { var book = await actContext.Books.AddAsync(new Book { ISBN = isbn }); var user = await actContext.Users.AddAsync(new User { UserName = username }); await actContext.SaveChangesAsync(); reviewDto.ISBN = book.Entity.ISBN; reviewDto.BookId = book.Entity.Id; reviewDto.UserId = user.Entity.Id; } using (var assertContext = new LibrarySystemContext(options)) { var sut = new BookWebService(assertContext); await sut.ReturnBookAsync(reviewDto); } }
public async Task <IActionResult> Index() { var cities = await _repo.GetKsacities(); var userComents = await _repo.GetComments(); var averageRate = await _repo.GetAverageRate(); var totalCount = await _repo.GetCommentCount(); var reviewDto = new ReviewDto { ServiceDto = new RequestedServiceDto { Ksacities = cities.Select(a => new cityDto { Id = a.Id, Name = a.Name }).ToList() }, UserComments = userComents.Select(a => new UserCommentsDto { CommentDate = a.CommentDate, CommentText = a.CommentText, Rating = a.Rating, UserEmail = a.UserEmail, UserFullName = a.UserFullName, RequestServiceId = a.RequestServiceId }).ToList(), AvaregRate = (int)averageRate, TotalRates = totalCount }; return(View(reviewDto)); }
public async Task ThrowExeptionWhenBookIdIsNullReturnBook_Test() { var title = "TestTitle"; var username = "******"; var reviewDto = new ReviewDto(); var lendDto = new BaseTitleDto(); var options = TestUtilities.GetOptions(nameof(ThrowExeptionWhenBookIdIsNullReturnBook_Test)); using (var actContext = new LibrarySystemContext(options)) { var book = await actContext.Books.AddAsync(new Book { Title = title }); var user = await actContext.Users.AddAsync(new User { UserName = username }); await actContext.SaveChangesAsync(); reviewDto.UserId = user.Entity.Id; lendDto.UserId = user.Entity.Id; var bookLending = new BookWebService(actContext); await bookLending.LendBookAsync(lendDto); } using (var assertContext = new LibrarySystemContext(options)) { var sut = new BookWebService(assertContext); await sut.ReturnBookAsync(reviewDto); } }
// Létrehozás public async Task <ReviewDto> CreateReviewAsync(ReviewDto newReviewDto) { Review review = mapper.Map <Review>(newReviewDto); var result = await reviewRepository.CreateReview(review); return(mapper.Map <ReviewDto>(result)); }
public async Task <ApiResponse> addComment([FromForm] ReviewDto dto) { try { //var comment = _mapper.Map<Review>(dto); Review newRe = new Review(); MemoryStream ms = new MemoryStream(); if (dto.Image != null) { dto.Image.CopyTo(ms); newRe.Image = ms.ToArray(); ms.Close(); ms.Dispose(); } newRe.ProductId = dto.ProductId; newRe.UserId = dto.UserId; newRe.Comment = dto.Comment; newRe.Date = DateTime.Now; await _reviewService.AddAsync(newRe); var vm = _mapper.Map <ReviewViewModel>(newRe); return(new ApiResponse("success", vm, 200)); }catch (Exception ex) { return(new ApiResponse($"{ex}", ex, 400)); } }
public async Task <ActionResult <Review> > PostReview(ReviewDto reviewDto) { var review = new Review(); if (reviewDto.AssignmentID != 0) { review = new Review { UserIDSender = reviewDto.SenderID, Description = reviewDto.description, AssignmentID = reviewDto.AssignmentID }; } else { review = new Review { UserIDSender = reviewDto.SenderID, Description = reviewDto.description, UserIDReceiver = reviewDto.ReceiverID }; } _context.Reviews.Add(review); await _context.SaveChangesAsync(); return(CreatedAtAction("GetReview", new { id = review.ReviewID }, review)); }
/// <inheritdoc /> public Result UpdateReview(ReviewDto reviewDto) { try { var review = _context.Reviews.FirstOrDefault(x => x.Id == reviewDto.Id); var product = _context.Products.Find(reviewDto.ProductId); if (review == null) { return(Result.Fail("Отзыв не отредактирован. Попробуйте снова.")); } review.Product = product; review.Author = reviewDto.Author; review.DateCreate = DateTime.Now; review.Status = reviewDto.Status; review.TextReview = reviewDto.TextReview; review.Rating = reviewDto.Rating; _context.Reviews.Update(review); _context.SaveChanges(); return(Result.Ok()); } catch (Exception e) { throw new ApplicationException(e.Message); } }
public IActionResult GetReviewByid(int reviewId) { var review = _reviewRepository.GetReviewById(reviewId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { if (review == null) { return(NotFound($"the review with the reviewId of {reviewId}, can not be found.")); } } catch (Exception ex) { _logger.LogError("there was an error in getting GetReviewById", ex); return(StatusCode(500)); } var reviewDto = new ReviewDto() { Id = review.Id, HeadLine = review.HeadLine, Rating = review.Rating, ReviewText = review.ReviewText }; return(Ok(reviewDto)); }
public async Task <IActionResult> AddReview(ReviewDto reviewDto) { var book = _bookService.GetDetail(reviewDto.BookId); //Get User duoc Like var user = await _reviewService.GetUserWithReviews(reviewDto.AccountId); // Get minh ra tu bang like if (book == null) { return(NotFound()); } var userReview = await _reviewService.GetUserReview(reviewDto.AccountId, reviewDto.BookId); if (userReview != null) { return(BadRequest("Bạn không thể thích sách này 2 lần !")); } userReview = new Review { AccountId = reviewDto.AccountId, Email = reviewDto.Email, BookId = reviewDto.BookId, CreatedAt = DateTime.Now, Content = reviewDto.Content }; _reviewService.repository.context.Reviews.Add(userReview); if (await _reviewService.repository.context.SaveChangesAsync() > 0) { return(Ok(userReview)); } return(BadRequest("Có lỗi xảy ra")); }
public Details() { IsValidProductId = true; IsLoading = IsPublishingReview = IsChangingFavorite = IsFavorite = false; PublicationMessage = FavoriteChangedMessage = ""; ReviewForm = new ReviewDto(); }
public ReviewDto Get(Guid id) { ReviewDto dto = new ReviewDto(); var connStr = Properties.Resources.ConnectionString; using (OdbcConnection connection = new OdbcConnection(connStr)) { connection.Open(); string queryStr = string.Format(@"SELECT * " + @"FROM {0} " + @"WHERE {1} = '{2}'", Properties.Resources.ReviewTable, Properties.Resources.ReviewIdColumn, id.ToString()); OdbcCommand cmd = new OdbcCommand(queryStr, connection); var reader = cmd.ExecuteReader(System.Data.CommandBehavior.SingleResult); if (reader.Read()) { dto.Id = reader.GetGuid(reader.GetOrdinal(Properties.Resources.ReviewIdColumn)); dto.Rating = reader.GetInt32(reader.GetOrdinal(Properties.Resources.ReviewRatingColumn)); dto.Comments = reader.GetString(reader.GetOrdinal(Properties.Resources.ReviewCommentsColumn)); dto.CustomerId = reader.GetGuid(reader.GetOrdinal(Properties.Resources.ReviewCustomerIdColumn)); } else { throw new ReviewDataException(); } } return(dto); }
public IList <ReviewDto> GetAll() { List <ReviewDto> allDtos = new List <ReviewDto>(); var connStr = Properties.Resources.ConnectionString; using (OdbcConnection connection = new OdbcConnection(connStr)) { connection.Open(); string queryStr = string.Format(@"SELECT * " + @"FROM {0}", Properties.Resources.ReviewTable); OdbcCommand cmd = new OdbcCommand(queryStr, connection); var reader = cmd.ExecuteReader(); while (reader.Read()) { var dto = new ReviewDto(); dto.Id = reader.GetGuid(reader.GetOrdinal(Properties.Resources.ReviewIdColumn)); dto.Rating = reader.GetInt32(reader.GetOrdinal(Properties.Resources.ReviewRatingColumn)); dto.Comments = reader.GetString(reader.GetOrdinal(Properties.Resources.ReviewCommentsColumn)); dto.CustomerId = reader.GetGuid(reader.GetOrdinal(Properties.Resources.ReviewCustomerIdColumn)); allDtos.Add(dto); } } return(allDtos); }
public async Task <IActionResult> CreateReview([FromQuery] ReviewDto reviewDto) { try { if (reviewDto == null) { _loggerManager.LogError("ReviewDto object sent from client is null."); return(BadRequest("ReviewDto object is null")); } if (!ModelState.IsValid) { _loggerManager.LogError("Invalid reviewDto object sent from client."); return(BadRequest("Invalid model object")); } var review = _mapper.Map <Review>(reviewDto); review.SubmissionDate = DateTime.UtcNow; await _repositoryWrapper.Review.CreateReview(review); if (review.IsEmptyObject()) { _loggerManager.LogError($"Save operation failed inside CreateReview action"); return(StatusCode(500, "Internal server error while saving review")); } var dbObject = await _repositoryWrapper.Review.GetReviewById(review.Id); return(Ok(dbObject)); } catch (Exception ex) { _loggerManager.LogError($"Something went wrong inside CreateReview action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public async Task <ActionResult> Put(int id, [FromBody] ReviewDto newReview) { try { var reviewWaitingForUpdate = await _context.Reviews.FirstOrDefaultAsync(r => r.ReviewId == id); if (reviewWaitingForUpdate == null) { return(NotFound()); } if (newReview.Stars >= 0 && newReview.Stars <= 5) { reviewWaitingForUpdate.Stars = newReview.Stars; } if (newReview.Description != null && newReview.Description != "") { reviewWaitingForUpdate.Description = newReview.Description; } await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(418, ex.Message)); } }
/// <inheritdoc /> public async Task <Result> AddReview(ReviewDto reviewDto) { try { var product = await _context.Products.FindAsync(reviewDto.ProductId); var review = new Review { Product = product, Author = reviewDto.Author, DateCreate = reviewDto.DateCreate, Status = reviewDto.Status, TextReview = reviewDto.TextReview, Rating = reviewDto.Rating }; _context.Add(review); _context.SaveChanges(); return(Result.Ok()); } catch (Exception e) { Console.WriteLine(e); throw; } }
public HttpResponseMessage AddJob([FromBody] ReviewDto reviewDto) { return(HandleRequestSafely(() => { if (reviewDto == null) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Body can't be null"); } var review = new ReviewFactory().GetReview(reviewDto); review.Job = _jobService.GetById(review.Job.Id); if (review.Job == null) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Review doesn't exist"); } if (review.Job.Asignee == null) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Review must have an asignee"); } if (review.Job.Review == null) { _reviewService.Add(review); } else { review.Id = review.Job.Review.Id; _reviewService.Update(review); } return Request.CreateResponse(HttpStatusCode.OK); })); }
private async Task <IActionResult> CreateOrEdit([FromBody] ReviewDto reviewDto) { GetTokenDetails(); if (!await _reviewRepo.ValidAuthId(reviewDto.CustomerId, authId)) { return(Forbid()); } if (!ValidReview(reviewDto)) { return(UnprocessableEntity()); } if (await _reviewRepo.PurchaseExists(reviewDto.CustomerId, reviewDto.ProductId)) { var review = await _reviewRepo.GetReview(reviewDto.CustomerId, reviewDto.ProductId, staff : false); if (review != null && !review.Visible) { return(NotFound()); } reviewDto.TimeStamp = ValidateDate(reviewDto.TimeStamp); if (review == null) { if (await _reviewRepo.NewReview(_mapper.Map <ReviewModel>(reviewDto))) { return(Ok()); } } if (await _reviewRepo.EditReview(_mapper.Map <ReviewModel>(reviewDto))) { return(Ok()); } } return(NotFound()); }
public static ReviewDto ReviewEntityToDto(Review entity, ReviewDto dto = null) { if (entity == null) { return(null); } dto = dto ?? new ReviewDto(); dto.Id = entity.Id; dto.StoreId = entity.StoreId; dto.ProductReference = entity.ProductReference; dto.CustomerReference = entity.CustomerReference; dto.Rating = entity.Rating; dto.Title = entity.Title; dto.Email = entity.Email; dto.Name = entity.Name; dto.Body = entity.Body; dto.VerifiedBuyer = entity.VerifiedBuyer; dto.RecommendProduct = entity.RecommendProduct; dto.CreateDate = entity.CreateDate; dto.UpdateDate = entity.UpdateDate; dto.Status = ReviewStatusToDto(entity.Status); dto.Comments = entity.Comments?.Select(x => CommentEntityToDto(x)).ToList() ?? new List <CommentDto>(); return(dto); }
public async Task GetReviewWithReviewId_ShouldOk() { var testReviewDto = new ReviewDto { reviewId = 1, productId = 1, userId = 1, userName = "******", reviewRating = 5, reviewContent = "Great Product. You can believe me, I'm not a bot.", hidden = false }; var mock = new Mock <IReviewService>(MockBehavior.Strict); mock.Setup(repo => repo.GetReviewAsync(1)).ReturnsAsync(testReviewDto).Verifiable(); var controller = new ReviewController(mock.Object); var result = await controller.GetReviewAsync(1); var controllerResult = result as OkObjectResult; Assert.IsNotNull(controllerResult); Assert.IsNotNull(controllerResult); var reviewsResult = controllerResult.Value as ReviewDto; Assert.IsNotNull(reviewsResult); Assert.AreEqual(testReviewDto.productId, reviewsResult.productId); Assert.AreEqual(testReviewDto.userId, reviewsResult.userId); Assert.AreEqual(testReviewDto.userName, reviewsResult.userName); Assert.AreEqual(testReviewDto.reviewRating, reviewsResult.reviewRating); Assert.AreEqual(testReviewDto.reviewContent, reviewsResult.reviewContent); mock.Verify(); mock.Verify(repo => repo.GetReviewAsync(1), Times.Once); }
public IActionResult GetReview(int reviewId) { if (!_reviewRepository.ReviewExists(reviewId)) { return(NotFound()); } var review = _reviewRepository.GetReview(reviewId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var reviewDto = new ReviewDto { Id = review.Id, Headline = review.Headline, ReviewText = review.ReviewText, Rating = review.Rating }; return(Ok(reviewDto)); }
public IEnumerable <IReview> GetAll(int movieId) { _connection.SqlConnection.Open(); var cmd = new MySqlCommand("SELECT * FROM review WHERE `MovieId` = @MovieId", _connection.SqlConnection); cmd.Parameters.AddWithValue("@MovieId", movieId); var reader = cmd.ExecuteReader(); var reviewRecords = new List <IReview>(); while (reader.Read()) { var review = new ReviewDto { ReviewId = (int)reader["ReviewId"], Review = reader["Review"]?.ToString(), Rating = (int)reader["Rating"], MovieId = (int)reader["MovieId"] }; reviewRecords.Add(review); } _connection.SqlConnection.Close(); return(reviewRecords); }
public ReviewDto Create() { //CREATE THE DTO ReviewDto dto = new ReviewDto() { Id = Guid.NewGuid(), Rating = int.Parse(Properties.Resources.DefaultReviewRating), Comments = Properties.Resources.DefaultReviewComments, CustomerId = Guid.Empty }; //INSERT INTO THE DB var connStr = Properties.Resources.ConnectionString; using (OdbcConnection connection = new OdbcConnection(connStr)) { connection.Open(); string queryStr = string.Format(@"INSERT INTO {0} " + @"({1}, {2}, {3}, {4}) " + @"VALUES('{5}','{6}', '{7}','{8}');", Properties.Resources.ReviewTable, Properties.Resources.ReviewIdColumn, Properties.Resources.ReviewRatingColumn, Properties.Resources.ReviewCommentsColumn, Properties.Resources.ReviewCustomerIdColumn, dto.Id, dto.Rating, dto.Comments, dto.CustomerId); var cmd = connection.CreateCommand(); cmd.CommandText = queryStr; var numRowsAffected = cmd.ExecuteNonQuery(); } //RETURN OUR INSERTED DTO return dto; }
private void HideSensitiveData(ReviewDto review) { if (review.IsAnonymous) { review.CreatedBy = PLACEHOLDER; } }
public ReviewDto Get(Guid id) { ReviewDto dto = new ReviewDto(); var connStr = Properties.Resources.ConnectionString; using (OdbcConnection connection = new OdbcConnection(connStr)) { connection.Open(); string queryStr = string.Format(@"SELECT * " + @"FROM {0} " + @"WHERE {1} = '{2}'", Properties.Resources.ReviewTable, Properties.Resources.ReviewIdColumn, id.ToString()); OdbcCommand cmd = new OdbcCommand(queryStr, connection); var reader = cmd.ExecuteReader(System.Data.CommandBehavior.SingleResult); if (reader.Read()) { dto.Id = reader.GetGuid(reader.GetOrdinal(Properties.Resources.ReviewIdColumn)); dto.Rating = reader.GetInt32(reader.GetOrdinal(Properties.Resources.ReviewRatingColumn)); dto.Comments = reader.GetString(reader.GetOrdinal(Properties.Resources.ReviewCommentsColumn)); dto.CustomerId = reader.GetGuid(reader.GetOrdinal(Properties.Resources.ReviewCustomerIdColumn)); } else throw new ReviewDataException(); } return dto; }
public ReviewDto Update(ReviewDto dto) { var connStr = Properties.Resources.ConnectionString; using (OdbcConnection connection = new OdbcConnection(connStr)) { connection.Open(); string queryStr = string.Format(@"UPDATE {0} " + //Update Reviews table @"SET {1} = '{2}', " + //Set Rating = dto.Rating @"{3} = '{4}' " + //Set Comments = dto.Comments @"{5} = '{6}' " + //Set CustomerId = dto.CustomerId @"WHERE {7} = '{8}'", //Where Id = 'id' Properties.Resources.ReviewTable, Properties.Resources.ReviewRatingColumn, dto.Rating, Properties.Resources.ReviewCommentsColumn, dto.Comments, Properties.Resources.ReviewCustomerIdColumn, dto.CustomerId, Properties.Resources.ReviewIdColumn, dto.Id); OdbcCommand cmd = new OdbcCommand(queryStr, connection); var numRowsAffected = cmd.ExecuteNonQuery(); } return(dto); }
public async Task <IActionResult> UpdateReview(Guid id, [FromQuery] ReviewDto reviewDto) { try { if (reviewDto == null) { _loggerManager.LogError("ReviewDto object sent from client is null."); return(BadRequest("ReviewDto object is null")); } if (!ModelState.IsValid) { _loggerManager.LogError("Invalid ReviewDto object sent from client."); return(BadRequest("Invalid ReviewDto model object")); } var dbReview = await _repositoryWrapper.Review.GetReviewById(id); if (dbReview.IsEmptyObject()) { _loggerManager.LogError($"Review with id: {id}, hasn't been found in db."); return(NotFound()); } var review = _mapper.Map <Review>(reviewDto); await _repositoryWrapper.Review.UpdateReview(dbReview, review); return(NoContent()); } catch (Exception ex) { _loggerManager.LogError($"Something went wrong inside UpdateReview action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public ReviewDto Create() { //CREATE THE DTO ReviewDto dto = new ReviewDto() { Id = Guid.NewGuid(), Rating = int.Parse(Properties.Resources.DefaultReviewRating), Comments = Properties.Resources.DefaultReviewComments, CustomerId = Guid.Empty }; //INSERT INTO THE DB var connStr = Properties.Resources.ConnectionString; using (OdbcConnection connection = new OdbcConnection(connStr)) { connection.Open(); string queryStr = string.Format(@"INSERT INTO {0} " + @"({1}, {2}, {3}, {4}) " + @"VALUES('{5}','{6}', '{7}','{8}');", Properties.Resources.ReviewTable, Properties.Resources.ReviewIdColumn, Properties.Resources.ReviewRatingColumn, Properties.Resources.ReviewCommentsColumn, Properties.Resources.ReviewCustomerIdColumn, dto.Id, dto.Rating, dto.Comments, dto.CustomerId); var cmd = connection.CreateCommand(); cmd.CommandText = queryStr; var numRowsAffected = cmd.ExecuteNonQuery(); } //RETURN OUR INSERTED DTO return(dto); }
public async Task <ReviewDto> CreateReviewAsync(ReviewDto model) { var entity = await _reviewRepository .InsertAsync(model.ToEntity()); return(entity.ToViewModel()); }
public IActionResult Post(int companyId, [FromBody] ReviewDto dto) { try { var customerExtarnalId = User.GetExternalId(); if (customerExtarnalId != dto.CustomerId) { return(Forbid()); } var customer = _customerRepository.GetByExternalId(customerExtarnalId); if (customer == null) { return(Forbid()); } if (dto.Rating < 1 || dto.Rating > 5) { return(BadRequest("rating cannot be less than 1 and greater than 5")); } dto.Date = DateTime.Now; var model = new Core.Entities.Review(); DtoToReviewMapper.Map(dto, model); _reviewRepository.Add(model); _unitOfWork.Save(); dto.Id = model.Id; return(Created($"api/companies/{companyId}/reviews/{model.Id}", dto)); } catch (Exception ex) { Log.Error(ex, $"unhandled exception"); return(StatusCode(500, ex)); } }
public IHttpActionResult Review(ReviewDto reviewDto) { var organizationfactors = _context.OrganizationFactors.Where(c => c.Organization.Id == reviewDto.organizationId).ToList(); var reviewInDB = _context.Reviews.SingleOrDefault(c => c.clientId == reviewDto.clientId && c.organizationId == reviewDto.organizationId); float total_rate = 0; foreach (var rate in reviewDto.ratedFactors) { total_rate += rate; } if (reviewInDB == null) { Review review = new Review() { generalFeedback = reviewDto.generalFeedback, clientId = reviewDto.clientId, organizationId = reviewDto.organizationId, TotalRate = total_rate / (reviewDto.ratedFactors.Count * 10), Date = DateTime.Now }; _context.Reviews.Add(review); var client = _context.Clients.SingleOrDefault(c => c.Id == reviewDto.clientId); client.Points = client.Points + 20; _context.SaveChanges(); var i = 0; foreach (var orgfactor in organizationfactors) { ReviewFactors reviewFactors = new ReviewFactors() { Rate = reviewDto.ratedFactors[i], organizationFactorId = orgfactor.Id, reviewId = review.Id }; i++; _context.ReviewFactors.Add(reviewFactors); } _context.SaveChanges(); updateRating(reviewDto.organizationId); } else { reviewInDB.generalFeedback = reviewDto.generalFeedback; reviewInDB.Date = DateTime.Now; reviewInDB.TotalRate = total_rate / (reviewDto.ratedFactors.Count * 10); var reviewFactorsInDB = _context.ReviewFactors.Where(c => c.reviewId == reviewInDB.Id).ToList(); var i = 0; foreach (var reviewFactor in reviewFactorsInDB) { var reviewFactorInDB = _context.ReviewFactors.SingleOrDefault(c => c.Id == reviewFactor.Id); reviewFactorInDB.Rate = reviewDto.ratedFactors[i]; i++; } _context.SaveChanges(); updateRating(reviewDto.organizationId); } return(Ok()); }
public static ReviewDto WriteReview(RecordingDataSet.Review review) { ReviewDto reviewDto = new ReviewDto(); reviewDto.id = review.Id; reviewDto.reviewContent = review.Content; reviewDto.rating = review.Rating; reviewDto.reviewerName = review.Reviewer.Name; return reviewDto; }
public void MakeReview() { RecordingDataSet recordingDataSet = new RecordingDataSet(); reviewer = recordingDataSet.Reviewers.NewReviewer(); reviewer.Id = 1; reviewer.Name = "Reviewer"; recordingDataSet.Reviewers.AddReviewer(reviewer); review = recordingDataSet.Reviews.NewReview(); review.Id = 1; review.Content = "Review Content"; review.Rating = 2; review.Reviewer = reviewer; recordingDataSet.Reviews.AddReview(review); reviewDto = RecordingAssembler.WriteReview(review); }
public ReviewDto Update(ReviewDto dto) { var connStr = Properties.Resources.ConnectionString; using (OdbcConnection connection = new OdbcConnection(connStr)) { connection.Open(); string queryStr = string.Format(@"UPDATE {0} " + //Update Reviews table @"SET {1} = '{2}', " + //Set Rating = dto.Rating @"{3} = '{4}' " + //Set Comments = dto.Comments @"{5} = '{6}' " + //Set CustomerId = dto.CustomerId @"WHERE {7} = '{8}'", //Where Id = 'id' Properties.Resources.ReviewTable, Properties.Resources.ReviewRatingColumn, dto.Rating, Properties.Resources.ReviewCommentsColumn, dto.Comments, Properties.Resources.ReviewCustomerIdColumn, dto.CustomerId, Properties.Resources.ReviewIdColumn, dto.Id); OdbcCommand cmd = new OdbcCommand(queryStr, connection); var numRowsAffected = cmd.ExecuteNonQuery(); } return dto; }
public IList<ReviewDto> GetAll() { List<ReviewDto> allDtos = new List<ReviewDto>(); var connStr = Properties.Resources.ConnectionString; using (OdbcConnection connection = new OdbcConnection(connStr)) { connection.Open(); string queryStr = string.Format(@"SELECT * " + @"FROM {0}", Properties.Resources.ReviewTable); OdbcCommand cmd = new OdbcCommand(queryStr, connection); var reader = cmd.ExecuteReader(); while (reader.Read()) { var dto = new ReviewDto(); dto.Id = reader.GetGuid(reader.GetOrdinal(Properties.Resources.ReviewIdColumn)); dto.Rating = reader.GetInt32(reader.GetOrdinal(Properties.Resources.ReviewRatingColumn)); dto.Comments = reader.GetString(reader.GetOrdinal(Properties.Resources.ReviewCommentsColumn)); dto.CustomerId = reader.GetGuid(reader.GetOrdinal(Properties.Resources.ReviewCustomerIdColumn)); allDtos.Add(dto); } } return allDtos; }