public async Task <int?> RateSeries(string userId, RateApiRequestModel model)
        {
            var series = this.dbContext.Series.Find(model.Id);

            if (series != null)
            {
                var userSeries = series.UsersSeries.FirstOrDefault(us => us.UserId == userId);

                if (userSeries == null)
                {
                    userSeries = new UserSeries
                    {
                        UserId   = userId,
                        SeriesId = model.Id,
                        Score    = model.Score,
                    };

                    series.UsersSeries.Add(userSeries);

                    this.dbContext.Update(series);
                    await this.dbContext.SaveChangesAsync();
                }
                else
                {
                    userSeries.Score = model.Score;

                    this.dbContext.Update(series);
                    await this.dbContext.SaveChangesAsync();
                }

                return(model.Score);
            }

            return(null);
        }
示例#2
0
        public async Task <int?> RateVolume(string userId, RateApiRequestModel model)
        {
            var volume = this.dbContext.Volumes.Find(model.Id);

            if (volume != null)
            {
                var userVolume = volume.UsersVolumes.FirstOrDefault(ua => ua.UserId == userId);

                if (userVolume == null)
                {
                    userVolume = new UserVolume
                    {
                        UserId   = userId,
                        VolumeId = model.Id,
                        Score    = model.Score,
                    };

                    volume.UsersVolumes.Add(userVolume);

                    this.dbContext.Update(volume);
                    await this.dbContext.SaveChangesAsync();
                }
                else
                {
                    userVolume.Score = model.Score;

                    this.dbContext.Update(volume);
                    await this.dbContext.SaveChangesAsync();
                }

                return(model.Score);
            }

            return(null);
        }
        public async Task <int?> RateArc(string userId, RateApiRequestModel model)
        {
            var arc = this.dbContext.Arcs.Find(model.Id);

            if (arc != null)
            {
                var userArc = arc.UsersArcs.FirstOrDefault(ua => ua.UserId == userId);

                if (userArc == null)
                {
                    userArc = new UserArc
                    {
                        UserId = userId,
                        ArcId  = model.Id,
                        Score  = model.Score,
                    };

                    arc.UsersArcs.Add(userArc);

                    this.dbContext.Update(arc);
                    await this.dbContext.SaveChangesAsync();
                }
                else
                {
                    userArc.Score = model.Score;

                    this.dbContext.Update(arc);
                    await this.dbContext.SaveChangesAsync();
                }

                return(model.Score);
            }

            return(null);
        }
示例#4
0
        public async Task <int?> RateIssue(string userId, RateApiRequestModel model)
        {
            var issue = this.dbContext.Issues.Find(model.Id);

            if (issue != null)
            {
                var userIssue = issue.UsersIssues.FirstOrDefault(ui => ui.UserId == userId);

                if (userIssue == null)
                {
                    userIssue = new UserIssue
                    {
                        UserId  = userId,
                        IssueId = model.Id,
                        Score   = model.Score,
                    };

                    issue.UsersIssues.Add(userIssue);

                    this.dbContext.Update(issue);
                    await this.dbContext.SaveChangesAsync();
                }
                else
                {
                    userIssue.Score = model.Score;

                    this.dbContext.Update(issue);
                    await this.dbContext.SaveChangesAsync();
                }

                return(model.Score);
            }

            return(null);
        }
        public async Task <ActionResult <int> > ScoreVolume(RateApiRequestModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            this.cache.RemoveVolumeDetails(model.Id);

            return(await this.volumeRatingService.RateVolume(this.User.GetId(), model));
        }