Exemple #1
0
        public async Task SetRate(string articleId, int rate)
        {
            int          doubleRate = rate;
            var          userId     = (await GetCurrentUser()).Id;
            ArticleModel article    = _articleRepository.Get(new Guid(articleId));
            MarkModel    userMark   = article.Marks
                                      .FirstOrDefault(m => m.UserId == new Guid(userId));

            if (userMark != null)
            {
                userMark.Value = rate;
                _markRepository.Update(userMark);
            }
            else
            {
                MarkModel newMark = new MarkModel()
                {
                    UserId    = new Guid(userId),
                    ArticleId = new Guid(articleId),
                    Value     = doubleRate
                };
                article.Marks.Add(newMark);
                _articleRepository.Update(article);
            }
        }
Exemple #2
0
        public void SetMark(MarkPostViewModel model)
        {
            var mark = Mapper.Map <MarkPostViewModel, Mark>(model);

            var foundedMark = _markRepository.GetMark(mark.Date, mark.StudentId, mark.SubjectId);

            if (foundedMark == null)
            {
                if (mark.Value != 0)
                {
                    _markRepository.Create(mark);
                }
            }
            else
            {
                if (mark.Value == 0)
                {
                    _markRepository.Remove(foundedMark);
                }
                else
                {
                    foundedMark.Value = mark.Value;
                    _markRepository.Update(foundedMark);
                }
            }
        }