Example #1
0
        public async Task <CollaboratorViewModel> Remove(CollaboratorIdViewModel collaboratorIdViewModel)
        {
            var model = await _collaboratorRepository.GetByIdAsync(collaboratorIdViewModel.Id);

            if (model == null)
            {
                throw new Exception("Collaborator not found!");
            }

            model.ClosingDate = DateTime.Now;

            var validation = new CollaboratorDeleteValidation().Validate(model);

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

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

            var viewModel = _mapper.Map <CollaboratorViewModel>(model);

            return(viewModel);
        }
Example #2
0
        public async Task <IActionResult> Update(long id, [FromBody] Collaborator item)
        {
            if (item == null || item.Id != id)
            {
                return(BadRequest());
            }

            var userId = _userManager.GetUserId(HttpContext.User);
            var currentCollaborator = _collaboratorRepository.Find(item.ProjectID, userId);

            if (currentCollaborator == null || currentCollaborator.Permission != Permissions.Owner)
            {
                return(Unauthorized());
            }

            if (!_projectRepository.UserHasAccess(item.ProjectID, userId))
            {
                return(Unauthorized());
            }

            var collaborator = _collaboratorRepository.Find(id);

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

            collaborator.Permission = item.Permission;
            _collaboratorRepository.Update(collaborator);
            // Broadcast new collaborator
            var project = _projectRepository.Find(collaborator.ProjectID);
            await _projAndCollabHandler.Add(project.Id);

            return(NoContent());
        }
        public IComandResult Handle(UpdateCollaboratorComand comand)
        {
            var name     = new Name(comand.FirstName, comand.LastName);
            var document = new Document(comand.Document);
            var email    = new Email(comand.Email);
            var address  = new Address(comand.Street, comand.Number, comand.District, comand.City, comand.Country, comand.ZipCode);
            var idAdd    = _collaboratorRepository.Get(comand.Id).IdAddress;

            address.Id = idAdd;
            var phone        = new Phone(comand.Phone);
            var collaborator = new Collaborator(name, document, email, phone, address, comand.Salary, comand.ProjectName, comand.BirthDate, comand.JobTitle)
            {
                Id = comand.Id
            };

            AddNotifications(collaborator);
            AddNotifications(name);
            AddNotifications(document);
            AddNotifications(email);
            AddNotifications(address);
            AddNotifications(phone);
            if (IsInvalid())
            {
                return(null);
            }

            _collaboratorRepository.Update(collaborator);

            return(new CreateCollaboratorCommandResult(collaborator.Id, name.ToString(), email.Address));
        }
Example #4
0
        public async Task Update(Collaborator collaborator)
        {
            if (!IsValid(collaborator))
            {
                return;
            }

            await _collaboratorRepository.Update(collaborator);
        }
Example #5
0
 public IActionResult Update([FromForm] Models.Collaborator collaborator)
 {
     if (ModelState.IsValid)
     {
         collaboratorRepository.Update(collaborator);
         TempData["MSG_OK"] = Message.MSG_OK_002;
         return(RedirectToAction(nameof(Index)));
     }
     return(View());
 }
Example #6
0
 public IActionResult Update([FromForm] MyOwnStore.Models.Collaborator collaborator)
 {
     ModelState.Remove("Password");
     if (ModelState.IsValid)
     {
         _cRepo.Update(collaborator);
         TempData["MSG_A"] = "1";
         return(RedirectToAction("Index"));
     }
     return(View("Register", collaborator));
 }
Example #7
0
        public IActionResult Update([FromForm] Models.Collaborator collaborator, int id)
        {
            ModelState.Remove("Password");
            if (ModelState.IsValid)
            {
                _collaboratorRepository.Update(collaborator);

                TempData["MSG_S"] = Message.MSG_S001;

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Example #8
0
 public void Update(Collaborator collaborator, long id)
 {
     _collaboratorRepository.Update(collaborator, id);
 }
Example #9
0
 public Collaborator Update(Collaborator collaborator)
 {
     return(_collaboratorRepository.Update(collaborator));
 }