public HttpResponseMessage Delete([FromBody] RequestAllocation request)
        {
            var users      = request.Users;
            var clients    = request.Clients;
            var actionUser = request.ActionUser;

            DeleteAllocation(users, clients, actionUser);
            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
        public HttpResponseMessage GetToReallocateUsers([FromBody] RequestAllocation request)
        {
            var clients = request.ReallocatedClients;

            using (EverestPortalContext context = new EverestPortalContext())
            {
                var userClients = (from user in context.Users
                                   join
                                   uType in context.userType on user.UserTypeID equals uType.UserTypeID
                                   join
                                   clUser in context.userClient on user.UserID equals clUser.UserID

                                   into gCUsers
                                   from clUser in gCUsers.DefaultIfEmpty()
                                   where uType.UserTypeName != "External users"
                                   select new
                {
                    userID = user.UserID,
                    userName = user.UserName,
                    clientID = clUser.ClientID == null ? 0 : clUser.ClientID
                }).ToList();

                var toReallocationUser = userClients.GroupBy(x => x.userID)
                                         .Where(g => !g.Any(gi => clients.Contains(gi.clientID)))
                                         .Select(x => new {
                    userId   = x.Key,
                    userName = x.First().userName
                }).OrderBy(x => x.userName);



                var response = new
                {
                    data = toReallocationUser
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }
        }
        public HttpResponseMessage GetToReallocateClients([FromBody] RequestAllocation request)
        {
            var users = request.ReallocatedUsers;

            using (EverestPortalContext context = new EverestPortalContext())
            {
                var clientUsers = (from client in context.Clients
                                   join
                                   clUser in context.userClient on client.Id equals clUser.ClientID
                                   into gCUsers

                                   from clUser in gCUsers.DefaultIfEmpty()
                                   where clUser.user.userType.UserTypeName != "External users"

                                   select new
                {
                    clientId = client.Id,
                    clientName = client.Name,
                    userID = clUser.UserID == null ? 0 : clUser.UserID
                }).ToList();

                var toReallocationClient = clientUsers.GroupBy(x => x.clientId)
                                           .Where(g => !g.Any(gi => users.Contains(gi.userID)))
                                           .Select(x => new {
                    clientId   = x.Key,
                    clientName = x.First().clientName
                }).OrderBy(x => x.clientName);



                var response = new
                {
                    data = toReallocationClient
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response));
            }
        }
 public HttpResponseMessage Reallocate([FromBody] RequestAllocation request)
 {
     DeleteAllocation(request.Users, request.Clients, request.ActionUser);
     Allocate(request.ReallocatedUsers, request.ReallocatedClients, request.ActionUser);
     return(Request.CreateResponse(HttpStatusCode.Created));
 }
 public void CreateAllocation(RequestAllocation requestAllocStr)
 {
     _context.RequestAllocation.Add(requestAllocStr);
     _context.SaveChanges();
 }