Example #1
0
        public async Task <bool> AddTechnologyScoreAsync(TechnologyScore technology)
        {
            var exist = await _dataContext.TechnologyScore
                        .AsNoTracking()
                        .SingleOrDefaultAsync(c =>
                                              c.SourceUserID == technology.SourceUserID &&
                                              c.TargetUserID == technology.TargetUserID &&
                                              c.TechnologyID == technology.TechnologyID);

            if (exist != null)
            {
                technology.Id = exist.Id;
                _dataContext.TechnologyScore.Update(technology);
            }
            else
            {
                _dataContext.TechnologyScore.Add(technology);
            }
            var added = await _dataContext.SaveChangesAsync();

            return(added > 0);
        }
Example #2
0
        public async Task <IActionResult> Set([FromRoute] Guid userId, [FromRoute] Guid technologyId, [FromRoute] int score)
        {
            if (HttpContext.GetUserId() == userId.ToString())
            {
                return(Forbid());
            }

            var _score = score > 5 ? 5 : (score < 1 ? 1 : score);

            var newId = Guid.NewGuid();
            var newTechnologyScore = new TechnologyScore
            {
                Id           = newId.ToString(),
                SourceUserID = HttpContext.GetUserId(),
                TargetUserID = userId.ToString(),
                TechnologyID = technologyId.ToString(),
                Score        = _score
            };

            var created = await _technologyScoreService.AddTechnologyScoreAsync(newTechnologyScore);

            if (!created)
            {
                return(BadRequest(new { error = "Unable to set technology score" }));
            }

            var tech = await _technologyScoreService.GetTechnologyByIdAsync(userId, technologyId);

            await _hub.Clients.User(userId.ToString()).SendAsync("newmark", tech, _score, default(System.Threading.CancellationToken));

            var locationUri = HttpContext.GetLocationURI(Routes.User.Technology.Get)
                              .Replace("{userId}", userId.ToString())
                              .Replace("{technologyId}", technologyId.ToString());

            return(Created(locationUri, tech));
        }