Exemplo n.º 1
0
        public async Task <bool> Add(AddFeedbackDto dto)
        {
            var hasRecordOfToday = await _repo.GetUserTodayFeedbacks(dto.UserKey, AbortToken);

            if (hasRecordOfToday.Count > 0)
            {
                return(false);
            }

            var feedback = FeedBack.Create(dto.Title, dto.Content);

            feedback.SetFeedBackUser(dto.UserKey);
            feedback.SetTag(dto.Tag);
            await _repo.AddAsync(feedback);

            return(true);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] FeedbackCommand command)
        {
            try
            {
                var user = await _userManager.FindByNameAsync(User.Identity.Name);

                var receiver = (await _userInfo.GetUserProfileById(command.ReceiverId)).User;

                await _repository.AddAsync(new Feedback
                {
                    CreatorId    = user.Id,
                    ReceiverId   = receiver.Id,
                    Description  = command.Description,
                    ProposalId   = command.ProposalId,
                    CreationDate = DateTime.Now
                });

                if (command.Achievement != null)
                {
                    var achievement = _achievements.GetAll().Where(x => x.User.UserInfoId == command.ReceiverId && x.Code == command.Achievement).FirstOrDefault();

                    if (achievement == null)
                    {
                        await _achievements.AddAsync(new Achievement
                        {
                            Points = 1,
                            Code   = command.Achievement.GetValueOrDefault(),
                            UserId = receiver.Id
                        });
                    }
                    else
                    {
                        achievement.Points++;
                    }
                }

                await _unitOfWork.Commit();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }