Ejemplo n.º 1
0
        public IActionResult Share([FromRoute] int planId, [FromBody] ICollection <UserDto> usersToShare)
        {
            var plan = _repo.GetPlan(planId);

            if (plan == null)
            {
                return(NotFound("There is no plan with specified ID: " + planId));
            }

            var alreadyShared = _repo.GetShares(planId);
            var usersToAdd    = usersToShare.Where(us => !alreadyShared.Contains(us.Id)).Select(us => us.Id);
            var usersToRemove = alreadyShared.Where(us => !usersToShare.Select(us => us.Id).Contains(us));

            _repo.AddUsersToShare(plan, usersToAdd);
            _repo.RemoveUsersFromShare(plan, usersToRemove);

            return(Ok());
        }