예제 #1
0
        public async Task <IActionResult> Update(int id, [FromBody] Project item)
        {
            if (item == null || item.Id != id)
            {
                return(BadRequest());
            }

            var project = _projectRepository.Find(id);
            var userId  = _userManager.GetUserId(HttpContext.User);

            if (project == null)
            {
                return(NotFound());
            }

            var currentCollaborator = _collaboratorRepository.Find(project.Id, userId);

            if (currentCollaborator == null || currentCollaborator.Permission != Permissions.Owner)
            {
                return(Unauthorized());
            }
            else
            {
                project.Name = item.Name;
                _projectRepository.Update(project);
                // Broadcast update
                await _projAndCollabHandler.Add(project.Id);

                return(new NoContentResult());
            }
        }
예제 #2
0
        public void Create(Collaborator collaborator)
        {
            if (collaborator == null)
            {
                throw new DomainException($@"Não foi informado um colaborador!");
            }

            if (string.IsNullOrWhiteSpace(collaborator.Name))
            {
                throw new DomainException($@"Não foi informado o nome do colaborador!");
            }

            ICollection <Collaborator> collaborators = collaboratorRepository.Find(x => x.Name.ToUpper().Equals(collaborator.Name.ToUpper()));

            if (collaborators.Any(x => x.Actived))
            {
                throw new DomainException($@"Já existe o colaborador {collaborator.Name}");
            }

            collaborator.Enable();

            collaboratorRepository.Save(collaborator);
        }
예제 #3
0
        public bool HasWriteAccess(long projectId, string userId)
        {
            var collaborator = _collaboratorRepository.Find(projectId, userId);

            return(HasWriteAccess(collaborator));
        }
예제 #4
0
        public IActionResult GetById(long id)
        {
            var collaborator = _collaboratorRepository.Find(id);

            return(new ObjectResult(collaborator));
        }