Esempio n. 1
0
        private void Create(IssueViewModel viewModel)
        {
            int userId = HttpContext.Current.User.Identity.GetUserId <int>();

            if (!_groupService.IsGroupOwner(viewModel.GroupId, userId))
            {
                throw new ArgumentException("Wrong groupId or group does not belong to you");
            }

            var group = _groupService.Get(viewModel.GroupId);

            viewModel.IssueNumber = ++group.IssuesTotal;
            _groupRepository.Update(group);

            int     issueId = _issueRepository.Add(viewModel.ToEntity());
            Comment comment = new Comment()
            {
                CreatedAt = DateTime.Now,
                IssueId   = issueId,
                Text      = string.IsNullOrWhiteSpace(viewModel.Text)? string.Empty : viewModel.Text,
                UserId    = userId,
                IsEdited  = false
            };

            _commentRepository.Add(comment);
        }