public async Task UpsertRatingAsync(Guid userId, Guid movieId, decimal rating, CancellationToken cancellationToken = default) { using (MoviesDbContext context = _dbContextFactory()) { UserEntity user = context.Users.SingleOrDefault(a => a.Id == userId); if (user == null) { throw new UserNotFoundException($"User with ID {userId} not found"); } MovieEntity movie = context.Movies.SingleOrDefault(a => a.Id == movieId); if (movie == null) { throw new MovieNotFoundException($"Movie with ID {movieId} not found"); } RatingEntity entity = context.Ratings.SingleOrDefault(a => a.UserId == userId && a.MovieId == movieId) ?? new RatingEntity { User = user, Movie = movie, }; entity.Rating = rating; entity.DateSet = DateTimeOffset.UtcNow; await context.SaveChangesAsync(cancellationToken); } }
public void AddNewRating() { var myNewRate = new RatingEntity() { Id = new Guid("591C6ACC-191B-4539-A4B9-42C5C280E4B5"), Film = new FilmEntity { OriginalName = "Guns Akimbo", CzechName = "Guns Akimbo", CountryOfOrigin = "Canada", GenreOfFilm = Genre.ActionFilm, Description = "Nebudu spoilovat, ale je tam ten týpek z Harry Pottera ;)", ImageFilePath = @":C\Windows\filmFotka.jpg", LengthInMinutes = new TimeSpan(1, 35, 0) }, RatingInPercents = 75, TextRating = "Hodně dobrej film, #ZrovnaJsemZkouklJedenPo3Pivách, Doporučuji potomhle psát kód (y)" }; appDbContextTestUnit.Ratings.Add(myNewRate); appDbContextTestUnit.SaveChanges(); using (var tempDbContext = dbContextFactory.CreateDbContext()) { var retrievedRate = tempDbContext.Ratings .Include(i => i.Film) .Single(entity => entity.Id == myNewRate.Id); Assert.Equal(myNewRate, retrievedRate, RatingEntity.RatingEntityComparer); } }
private void AssertRatingEntity(RatingEntity actual, decimal?value, string explaination, string impact, string dataPoint) { Assert.Equal(value, actual.Value); Assert.Equal(explaination, actual.Explaination); Assert.Equal(impact, actual.Impact); Assert.Equal(dataPoint, actual.DataPoint); }
public JsonResultEntity Create([FromBody] RatingEntity ratingEntity) { RatingBL ratingBL = new RatingBL(); JsonResultEntity response = new JsonResultEntity(); try { var result = ratingBL.Create(ratingEntity); if (result.HasWarning()) { response.Message = String.Join(",", result.Warning); return(response); } response.Success = true; response.Data = result.Value; } catch (Exception ex) { response.Message = ex.Message; LoggerHelper.Error(ex); } return(response); }
public static RatingViewModel ToMVCRating(this RatingEntity ratingDal) { return(new RatingViewModel() { UserName = ratingDal.UserName, PhotoID = ratingDal.PhotoId, ID = ratingDal.Id }); }
public static DalRating ToDalRating(this RatingEntity ratingEntity) { return(new DalRating() { Id = ratingEntity.Id, UserName = ratingEntity.UserName, PhotoId = ratingEntity.PhotoId }); }
public RatingEntity Create(RatingEntity ratingEntity) { var query = @"INSERT INTO ""Rating""(""ContentType"",""ContentID"",""UserProfileID"",""Rate"",""Review"",""Like"",""CreatedDate"",""ModifiedDate"") VALUES(@ContentType,@ContentID,@UserProfileID,@Rate,@Review,@Like,@CreatedDate,@ModifiedDate) RETURNING ""ID"";"; int id = DbConnection.Query <int>(query, ratingEntity).Single(); ratingEntity.ID = id; return(ratingEntity); }
public static DalRating ToDalRating(this RatingEntity rating) { return(new DalRating { Id = rating.Id, SkillId = rating.SkillId, UserId = rating.UserId, Value = rating.Value }); }
public void AddRating(RatingEntity rating) { if (ReferenceEquals(rating, null)) { throw new ArgumentNullException(nameof(rating)); } photoRepository.AddRating(rating.ToDalRating()); uow.Commit(); }
public ResultEntity <RatingEntity> Create(RatingEntity ratingEntity) { var validationResult = new ResultEntity <RatingEntity>(); using (var ratingDA = new RatingDA()) { validationResult.Value = ratingDA.Create(ratingEntity); } return(validationResult); }
public static RatingDetailModel MapRatingEntityToDetailModel(RatingEntity entity) { return(new RatingDetailModel { Id = entity.Id, RatedMovieId = entity.RatedMovieId, Nick = entity.Nick, NumericEvaluation = entity.NumericEvaluation, Review = entity.Review }); }
public async Task Rate(RatingEntity entity, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (entity == null) { throw new ArgumentNullException(nameof(entity)); } await _organizationRepository.Rate(entity, cancellationToken); }
public int Update(RatingEntity ratingEntity) { int affectedRows = 0; if (IsHaveId <RatingEntity>(ratingEntity) == false) { var query = @"UPDATE ""Rating"" SET ""ContentType""=@ContentType,""ContentID""=@ContentID,""UserProfileID""=@UserProfileID,""Rate""=@Rate,""Review""=@Review,""Like""=@Like,""CreatedDate""=@CreatedDate,""ModifiedDate""=@ModifiedDate WHERE ""ID""=@ID"; affectedRows = DbConnection.Execute(query, ratingEntity); } return(affectedRows); }
public static DalRating ToDal(RatingEntity rating) { if (rating == null) { throw new ArgumentNullException(nameof(rating)); } return(new DalRating() { Id = rating.Id, UserId = rating.UserId, TextDescId = rating.TextDescId, Value = rating.Value }); }
public static RatingViewModel ToPlRating(this RatingEntity rating) { var user = new UserViewModel { Id = rating.UserId }; return(new RatingViewModel { Id = rating.Id, SkillId = rating.SkillId, User = user, Value = rating.Value }); }
public async Task AddUserKeywordRatingAsync(UserRating userRating) { var contributionRating = userRating.ReviewScore * 10; var ratingEntity = new RatingEntity { Username = userRating.Username, ContributionRating = contributionRating, Keyword = userRating.Keyword, }; await SetExpertSolvedCasesAsync(userRating.Username); await _ratingRepository.AddOrUpdateRatingAsync(ratingEntity); }
public static RatingViewModel ToMvcRating(this RatingEntity ratingEntity) { if (ratingEntity == null) { return(null); } return(new RatingViewModel() { Id = ratingEntity.Id, UserRate = ratingEntity.UserRate, PhotoId = ratingEntity.PhotoId, UserId = ratingEntity.UserId }); }
public static DalRating ToDalRating(this RatingEntity ratingEntity) { if (ratingEntity == null) { return(null); } return(new DalRating() { Id = ratingEntity.Id, UserId = ratingEntity.UserId, PhotoId = ratingEntity.PhotoId, UserRate = ratingEntity.UserRate }); }
// Adding and updating rating info. public async Task AddOrUpdateRatingAsync(RatingEntity rating) { var userRating = _context.Ratings.Where(t => t.Username == rating.Username && t.Keyword == rating.Keyword) .FirstOrDefault(); if (userRating == null) { _logger.LogInformation($"User with keyword was not in the list. Creating new record..."); _context.Add(rating); await _context.SaveChangesAsync(); } else { _logger.LogInformation($"User {userRating.Username} with keyword {userRating.Keyword} was found. Updating existing record..."); userRating.ContributionRating += rating.ContributionRating; await _context.SaveChangesAsync(); } }
public void AddNew_Rating_Persistent() { var rating = new RatingEntity() { Id = new Guid("d36ec7a6-469f-4b92-b1a4-cec54ec5dd02"), Nick = "SithJedi54", NumericEvaluation = 10, Review = "Twas AMAZING!" }; _testContext.MoviesDbContextSUT.Ratings.Add(rating); _testContext.MoviesDbContextSUT.SaveChanges(); using var dbx = _testContext.DbContextFactory.CreateDbContext(); var ratingFromDb = dbx.Ratings.First(r => r.Id == rating.Id); Assert.Equal(rating, ratingFromDb, RatingEntity.RatingComparer); }
public ResultEntity <RatingEntity> Update(RatingEntity ratingEntity) { var validationResult = new ResultEntity <RatingEntity>(); using (var ratingDA = new RatingDA()) { var resultUpdate = ratingDA.Update(ratingEntity); if (resultUpdate <= 0) { validationResult.Warning.Add("Failed Updating Rating!"); return(validationResult); } validationResult.Value = ratingEntity; } return(validationResult); }
public ActionResult Rating(int idPhoto) { var rating = new RatingEntity() { UserName = User.Identity.Name, PhotoId = idPhoto }; PhotoEntity photo = null; try { photo = _photoService.GetById(idPhoto); } catch { return(RedirectToAction("Error", "Error")); } var photoRating = new PhotoInformViewModel { PhotoId = photo.Id }; if (ReferenceEquals(photo.Ratings.FirstOrDefault(p => p.UserName == rating.UserName), null)) { _photoService.AddRating(rating); photoRating.IsSelected = true; } else { _photoService.DeleteRating(rating); photoRating.IsSelected = false; } try { photoRating.RatingsCount = _photoService.GetById(photo.Id).Ratings.Count; } catch { return(RedirectToAction("Error", "Error")); } return(Json(photoRating)); }
public async Task Rate(RatingEntity entity, CancellationToken cancellationToken) { var sqlCommand = new CommandDefinition(@" insert [dbo].[Ratings] (OrganizationId, UserId, Rating, Text) values(@organizationId, @userId, @rating, @text)", new { @organizationId = entity.OrganizationId, @userId = entity.UserId, @rating = entity.Rating, @text = entity.Text }, cancellationToken: cancellationToken); try { await Db.ExecuteAsync(sqlCommand); } catch (Exception ex) { throw; } }
public ActionResult AddRating(int skillId, int value, int fieldId) { bool isUpdate = _ratingService .GetSkillUserRatings(skillId, _userService.GetUserEntityByLogin(User.Identity.Name).Id) .Any(); if (!isUpdate) { var ratingEntity = new RatingEntity { UserId = _userService.GetUserEntityByLogin(User.Identity.Name).Id, Value = value, SkillId = skillId }; _ratingService.CreateRating(ratingEntity); } else { var ratingEntity = new RatingEntity { Id = _ratingService.GetSkillUserRatings(skillId, _userService.GetUserEntityByLogin(User.Identity.Name).Id).First(r => r.SkillId == skillId).Id, UserId = _userService.GetUserEntityByLogin(User.Identity.Name).Id, Value = value, SkillId = skillId }; _ratingService.UpdateRating(ratingEntity); } if (Request.IsAjaxRequest()) { return(PartialView("_Rated")); } return(RedirectToAction("Field", new { id = fieldId })); }
public void Delete(RatingEntity entity) { Remove(entity); }
private int Update(RatingBllModel rating, RatingEntity entity) { return(_floraDbContext.SaveChanges()); }
/// <summary> /// There are no comments for RatingEntitySet in the schema. /// </summary> public void AddToRatingEntitySet(RatingEntity ratingEntity) { base.AddObject("RatingEntitySet", ratingEntity); }
/// <summary> /// Create a new RatingEntity object. /// </summary> /// <param name="id">Initial value of id.</param> /// <param name="value">Initial value of value.</param> /// <param name="comments">Initial value of comments.</param> public static RatingEntity CreateRatingEntity(int id, int value, string comments) { RatingEntity ratingEntity = new RatingEntity(); ratingEntity.id = id; ratingEntity.value = value; ratingEntity.comments = comments; return ratingEntity; }
public void DeleteEntity(RatingEntity rating) { repository.Delete(rating.ToDalRating()); uow.Commit(); }
public void UpdateRating(RatingEntity rating) { ratingRepository.Update(rating.ToDalRating()); uow.Commit(); }