public async Task <IActionResult> PostRating([FromBody] RatingDto rating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var model  = RatingMapper.ConvertDtoToModel(rating);
                var result = _context.Rating.FirstOrDefault(r => r.UserId == model.UserId && r.GameId == model.GameId);
                if (result == null)
                {
                    _context.Rating.Add(model);
                }
                else
                {
                    result.Evaluation            = model.Evaluation;
                    _context.Entry(result).State = EntityState.Modified;
                }

                await _context.SaveChangesAsync();

                return(StatusCode(201));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Ejemplo n.º 2
0
 public void Update(RatingDetailModel model)
 {
     using (var dbContext = _dbContextSqlFactory.CreateDbContext())
     {
         var entity = RatingMapper.MapRatingDetailModelToEntity(model);
         dbContext.Ratings.Update(entity);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public IList <RatingDetailModel> GetAll()
 {
     using (var dbContext = _dbContextSqlFactory.CreateDbContext())
     {
         return(dbContext.Ratings
                .Select(e => RatingMapper.MapRatingEntityToDetailModel(e))
                .ToList());
     }
 }
Ejemplo n.º 4
0
        public RatingFacadeTests()
        {
            var dbContextFactory = new DbContextInMemoryFactory(nameof(ActorFacadeTest));
            var unitOfWork       = new UnitOfWork(dbContextFactory);

            repository = new Repository <RatingEntity>(unitOfWork);
            mapper     = new RatingMapper();

            facadeTestUnit = new RatingFacade(unitOfWork, repository, mapper);
        }
Ejemplo n.º 5
0
 public RatingDetailModel Create(RatingDetailModel model)
 {
     using (var dbContext = _dbContextSqlFactory.CreateDbContext())
     {
         var entity = RatingMapper.MapRatingDetailModelToEntity(model);
         dbContext.Ratings.Add(entity);
         dbContext.SaveChanges();
         return(RatingMapper.MapRatingEntityToDetailModel(entity));
     }
 }
Ejemplo n.º 6
0
 public IList <RatingDetailModel> GetAllByMovieId(Guid id)
 {
     using (var dbContext = _dbContextSqlFactory.CreateDbContext())
     {
         return(dbContext.Ratings
                .Where(t => t.RatedMovieId == id)
                .Select(e => RatingMapper.MapRatingEntityToDetailModel(e))
                .ToList());
     }
 }
Ejemplo n.º 7
0
        public async Task <ActionResult <PublicApi.v1.DTO.Rating> > GetRating(int id)
        {
            var rating = await _bll.Ratings.FindAsync(id);

            if (rating == null)
            {
                return(NotFound());
            }

            return(RatingMapper.MapFromBLL(rating));
        }
Ejemplo n.º 8
0
        public IActionResult GetChartData(string group, string subject, short year, short semester, string teacher)
        {
            var sheet = ExamSheetManager.Get(group, teacher, subject, year, semester, true);
            var model = new GroupChartJsonModel();

            if (sheet == null)
            {
                return(Json(model));
            }
            var semesterMarks = new Dictionary <string, short>();
            var rangeMarks    = new Dictionary <string, short>();
            var ratings       = RatingManager.FindAll(sheet.Id);

            model.StudentsRating = new List <StudentRating>();
            foreach (var rating in ratings)
            {
                var stringRepresentation = RatingMapper.MapRatingToString(rating.Mark);
                var rangeRepresentation  = RatingMapper.MapRatingToRange(rating.Mark);
                if (semesterMarks.ContainsKey(stringRepresentation))
                {
                    semesterMarks[stringRepresentation] = (short)(semesterMarks[stringRepresentation] + 1);
                }
                else
                {
                    semesterMarks[stringRepresentation] = 1;
                }
                if (rangeMarks.ContainsKey(rangeRepresentation))
                {
                    rangeMarks[rangeRepresentation] = (short)(rangeMarks[rangeRepresentation] + 1);
                }
                else
                {
                    rangeMarks[rangeRepresentation] = 1;
                }

                var student = StudentManager.GetById(rating.StudentId);
                model.StudentsRating.Add(new StudentRating()
                {
                    Surname = student.Surname, Name = student.Name, Rating = rating.Mark, StringRepresentation = stringRepresentation
                });
            }
            var sorted = semesterMarks.OrderBy(key => key.Key);

            model.SemesterMarks = sorted.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value);
            sorted               = rangeMarks.OrderBy(key => key.Key);
            model.RangeMarks     = sorted.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value);
            model.StudentsRating = model.StudentsRating.OrderByDescending(x => x.Rating).ToList();
            return(Json(model));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> PutRating(int id, PublicApi.v1.DTO.Rating rating)
        {
            if (id != rating.Id)
            {
                return(BadRequest());
            }

            // check, that the object being used is really belongs to logged in user
            if (!await _bll.Ratings.BelongsToUserAsync(rating.AppUserId, User.GetUserId()))
            {
                return(NotFound());
            }

            _bll.Ratings.Update(RatingMapper.MapFromExternal(rating));
            await _bll.SaveChangesAsync();

            return(NoContent());
        }
Ejemplo n.º 10
0
        public async Task <ActionResult <PublicApi.v1.DTO.Rating> > DeleteRating(int id)
        {
            var rating = await _bll.Ratings.FindAsync(id);

            if (rating == null)
            {
                return(NotFound());
            }

            // check, that the object being used is really belongs to logged in user
            if (!await _bll.Ratings.BelongsToUserAsync(rating.AppUserId, User.GetUserId()))
            {
                return(NotFound());
            }

            _bll.Ratings.Remove(rating);
            await _bll.SaveChangesAsync();

            return(RatingMapper.MapFromBLL(rating));
        }
        public async Task <MatchModel> CreateMatch(CreateMatchCommand command)
        {
            Player winner = await playersApiClient.GetPlayer(command.WinnerId);

            Player loser = await playersApiClient.GetPlayer(command.LoserId);

            PlayersRatings ratings = await ratingApiClient.CalculatePlayersRatings(RatingMapper.Map(winner, loser));

            UpdatePlayerRequest updateWinnerRequest = new UpdatePlayerRequest(winner.Id, winner.Name, ratings.WinnerRating.Rating, ratings.WinnerRating.Deviation, ratings.WinnerRating.Volatility);

            winner = await playersApiClient.UpdatePlayer(updateWinnerRequest);

            UpdatePlayerRequest updateLoserRequest = new UpdatePlayerRequest(loser.Id, loser.Name, ratings.LoserRating.Rating, ratings.LoserRating.Deviation, ratings.LoserRating.Volatility);

            loser = await playersApiClient.UpdatePlayer(updateLoserRequest);

            CreateMatchRequest createMatchRequest = new CreateMatchRequest(winner.Id, loser.Id, command.Score);
            Match match = await matchesApiClient.CreateMatch(createMatchRequest);

            return(MatchMapper.Map(match, new List <Player> {
                winner, loser
            }));
        }