Exemple #1
0
        public async Task <ActionResult> UpdateCollaborator(int id, [FromBody] CollaboratorInsertViewModel collaborator)
        {
            var collab = await _collaboratorService.GetByIdAsync(new CollaboratorIdViewModel(id));

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

            var updateModel = _collaboratorService.Update(id, collaborator);

            if (!updateModel == true)
            {
                return(BadRequest());
            }

            var deleteUser = await _userService.DeleteUserAsync(collab.Email);

            if (!deleteUser == true)
            {
                return(BadRequest());
            }

            var updateUser = await _userService.CreateUserAsync(collaborator);

            if (!updateUser == true)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
Exemple #2
0
        public async Task <CollaboratorViewModel> Add(CollaboratorInsertViewModel collaboratorInsertViewModel)
        {
            var collaborative = await _collaborativeRepository.GetByMail(_user.Email);

            if (collaborative == null)
            {
                throw new Exception("Collaborative not found!");
            }

            var model = _mapper.Map <Collaborator>(collaboratorInsertViewModel);

            model.CollaborativeId = collaborative.Id;

            var validation = new CollaboratorInsertValidation(_collaboratorRepository).Validate(model);

            if (!validation.IsValid)
            {
                throw new Exception("Collaborator is invalid!");
            }


            _collaboratorRepository.Add(model);
            _unitOfWork.Commit();

            model.Collaborative = collaborative;

            return(_mapper.Map <CollaboratorViewModel>(model));
        }
Exemple #3
0
        public async Task <ActionResult <CollaboratorViewModel> > PostCollaborator([FromBody] CollaboratorInsertViewModel collaborator)
        {
            if (collaborator == null)
            {
                return(NotFound());
            }

            var result = await _userService.CreateUserAsync(collaborator);

            if (!result == true)
            {
                return(BadRequest());
            }

            var created = Created(nameof(GetById), await _collaboratorService.Add(collaborator));

            if (created.Value == null)
            {
                await _userService.DeleteUserAsync(collaborator.Email);

                return(BadRequest());
            }

            return(created);
        }
Exemple #4
0
        public bool Update(int id, CollaboratorInsertViewModel collaboratorInsertViewModel)
        {
            var model = _mapper.Map <Collaborator>(collaboratorInsertViewModel);

            model.Id = id;

            var validation = new CollaboratorUpdateValidator(_collaboratorRepository).Validate(model);

            if (!validation.IsValid)
            {
                return(false);
            }

            _collaboratorRepository.Update(model);
            _unitOfWork.Commit();

            return(true);
        }