mercredi 1 février 2017

Best/Logical practice for properties values update (Controller or Service layer?)

My project got Web API Controller, Services and Repositories. Controller got an Update method like:

 public IActionResult Update(CreateCollaboratorViewModel collaboratorViewModel)
    {
        AdminCollaborators collaborator = new AdminCollaborators();
        collaborator.Description = collaboratorViewModel.Description;
        collaborator.ModifiedBy = _myContext.CurrentUserId;
        var output = _collaboratorService.UpdateCollaborator(collaborator, _myContext.CurrentUserId);
        return Ok(new WebApiResultValue(true, output, "update successful."));
    }

Service

 public AdminCollaborators UpdateCollaborator(AdminCollaborators collaborator, Guid actorUserId)
    {
        collaborator.ModifiedBy = actorUserId;
        collaborator.ModifiedOn = DateTimeHelper.Instance.GetCurrentDate();
        _collaboratorRepository.UpdateCollaborator(collaborator,actorUserId);
        return _collaborationRepository.SaveChanges();
    }

Normally Services are supposed to implement business logic (if im not wrong). Please advice should I update the properties values in Controller or Services.

Thanks

Aucun commentaire:

Enregistrer un commentaire