Exemplo n.º 1
0
        public CollaboratorViewModel Add(CollaboratorViewModel collaboratorViewModel)
        {
            var collaborator = _mapper.Map <CollaboratorViewModel, Collaborator>(collaboratorViewModel);

            _collaboratorService.Add(collaborator);
            return(collaboratorViewModel);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public CollaboratorViewModel Add(CollaboratorViewModel collaboratorViewModel)
        {
            var collaborator = _mapper.Map <CollaboratorViewModel, Collaborator>(collaboratorViewModel);

            _uow.BeginTransaction();
            var collaboratorReturn = _collaboratorService.Add(collaborator);

            _uow.Commit();

            collaboratorViewModel = _mapper.Map <Collaborator, CollaboratorViewModel>(collaboratorReturn);
            return(collaboratorViewModel);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create(CollaboratorViewModel collaboratorViewModel)
        {
            collaboratorViewModel = await FillCollaborator(collaboratorViewModel);

            if (!ModelState.IsValid)
            {
                return(View(collaboratorViewModel));
            }

            var collaborator = _mapper.Map <Collaborator>(collaboratorViewModel);

            await _collaboratorService.Add(collaborator);

            if (!ValidOperation())
            {
                return(View(collaboratorViewModel));
            }

            return(RedirectToAction("Index"));
        }