Esempio n. 1
0
        public async Task <ActionResult> PutCollaborative(int id, [FromBody] CollaborativeInsertViewModel collaborative)
        {
            var collab = await _collaborativeService.GetByIdAsync(new CollaborativeIdViewModel(id));

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

            var updateModel = _collaborativeService.Update(id, collaborative);

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

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

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

            var updateUser = await _userService.CreateUserAsync(collaborative);

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

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <ActionResult <CollaborativeViewModel> > PostCollaborative([FromBody] CollaborativeInsertViewModel collaborative)
        {
            if (collaborative == null)
            {
                return(NotFound());
            }

            var result = await _userService.CreateUserAsync(collaborative);

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

            var created = Created(nameof(GetById), _collaborativeService.Add(collaborative));

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

                return(BadRequest());
            }

            return(created);
        }
        public bool Update(int id, CollaborativeInsertViewModel collaborativeInsertViewModel)
        {
            var model = _mapper.Map <Collab>(collaborativeInsertViewModel);

            model.Id = id;

            var validation = new CollaborativeUpdateValidation(_collaborativeRepository).Validate(model);

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

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

            return(true);
        }
        public CollaborativeViewModel Add(CollaborativeInsertViewModel collaborativeInsertViewModel)
        {
            CollaborativeViewModel viewModel = null;

            var model = _mapper.Map <Collab>(collaborativeInsertViewModel);

            var validation = new CollaborativeInsertValidation(_collaborativeRepository).Validate(model);

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

            _collaborativeRepository.Add(model);

            _unitOfWork.Commit();

            viewModel = _mapper.Map <CollaborativeViewModel>(model);

            return(viewModel);
        }