public IHttpActionResult Add([FromBody] ClientGroupDto clientGroup)
        {
            try
            {
                if (clientGroup == null)
                {
                    return(BadRequest("Passed clientGroup is null!!"));
                }

                if (clientGroup.ClientId == null)
                {
                    return(BadRequest("Passed clientGroup doesn't have client!!"));
                }

                if (clientGroup.StudyGroupId == null)
                {
                    return(BadRequest("Passed clientGroup doesn't have study group!!"));
                }

                var exactClientGroup = _sqlDA.LoadData <ClientGroup, dynamic>("dbo.spClientGroups_GetByClientAndGroup", new { ClientId = clientGroup.ClientId, StudyGroupId = clientGroup.StudyGroupId })
                                       .FirstOrDefault();

                if (exactClientGroup != null)
                {
                    return(BadRequest("There is already the same active clientGroup!!"));
                }

                _sqlDA.SaveData <ClientGroupDto>("dbo.spClientGroups_Add", clientGroup);
                return(StatusCode(HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #2
0
        private void UpdateGroupViewModel(ClientGroupViewModel groupViewModel, ClientGroupDto groupDto)
        {
            groupViewModel.Name = groupDto.Name;
            if (groupDto.Clients != null)
            {
                _appDispatcher.Current.BeginInvoke(DispatcherPriority.Background, (Action)(() =>
                {
                    var toRemove = groupViewModel.Clients.ToList();
                    foreach (var clientId in groupDto.Clients)
                    {
                        var existingClient = groupViewModel.Clients.FirstOrDefault(x => x.ClientId == clientId);
                        if (existingClient != null)
                        {
                            toRemove.Remove(existingClient);
                        }
                        else
                        {
                            groupViewModel.Clients.Add(Clients[clientId]);
                        }
                    }

                    foreach (var clientViewModel in toRemove)
                    {
                        groupViewModel.Clients.Remove(clientViewModel);
                    }
                }));
            }
        }
Exemple #3
0
 private void OnClientGroupUpdated(ClientGroupDto obj)
 {
     if (Groups.TryGetValue(obj.ClientGroupId, out var groupViewModel))
     {
         UpdateGroupViewModel(groupViewModel, obj);
     }
 }
Exemple #4
0
        private void OnClientGroupCreated(ClientGroupDto obj)
        {
            var groupViewModel = new DefaultClientGroupViewModel(obj, Clients);

            if (Groups.TryAdd(groupViewModel.ClientGroupId, groupViewModel))
            {
                _appDispatcher.Current.BeginInvoke(DispatcherPriority.Background, (Action)(() => GroupViewModels.Add(groupViewModel)));
            }
        }
        public async Task <IActionResult> Update(int id, [FromBody] ClientGroupDto clientGroupDto, [FromServices] IUpdateClientGroupAction action)
        {
            clientGroupDto.ClientGroupId = id;

            var result = await action.ToRunner(_context).ExecuteAsync(clientGroupDto);

            return(await BizActionStatus(action, async() =>
            {
                await _hubContext.Clients.All.SendAsync(HubEventNames.ClientGroupUpdated, Mapper.Map <ClientGroupDto>(result));
                return Ok();
            }));
        }
        public async Task <IActionResult> Create([FromBody] ClientGroupDto clientGroupDto, [FromServices] ICreateClientGroupAction action)
        {
            var result = await action.ToRunner(_context).ExecuteAsync(clientGroupDto);

            return(await BizActionStatus(action, async() =>
            {
                clientGroupDto.ClientGroupId = result.ClientGroupId;
                await _hubContext.Clients.All.SendAsync(HubEventNames.ClientGroupCreated, clientGroupDto);

                return CreatedAtAction(nameof(GetGroup), new { id = result.ClientGroupId }, clientGroupDto);
            }));
        }
Exemple #7
0
        public async Task <ClientGroup> BizActionAsync(ClientGroupDto inputData)
        {
            var group = await _dbAccess.FindAsync(inputData.ClientGroupId);

            if (group == null)
            {
                return(ReturnError <ClientGroup>(BusinessErrors.ClientGroups.GroupNotFound));
            }

            group.Name = inputData.Name;
            return(group);
        }
Exemple #8
0
        public DefaultClientGroupViewModel(ClientGroupDto clientGroupDto, IDictionary <int, ClientViewModel> clients)
        {
            ClientGroupId = clientGroupDto.ClientGroupId;
            Name          = clientGroupDto.Name;

            var clientsCollection =
                new ObservableCollection <ClientViewModel>(clientGroupDto.Clients?.Select(x =>
            {
                var client = clients[x];
                client.Groups.Add(this);
                return(client);
            }) ?? Enumerable.Empty <ClientViewModel>());

            clientsCollection.CollectionChanged += ClientsCollectionOnCollectionChanged;

            Clients = clientsCollection;
        }
Exemple #9
0
        public Task <ClientGroup> BizActionAsync(ClientGroupDto inputData)
        {
            if (ValidateModelFailed(inputData))
            {
                return(Task.FromResult <ClientGroup>(null));
            }

            var clientGroup = new ClientGroup {
                Name = inputData.Name
            };

            if (inputData.Clients?.Count > 0)
            {
                clientGroup.ClientGroupMemberships = inputData.Clients.Select(x => new ClientGroupMembership {
                    ClientId = x
                }).ToList();
            }

            _dbAccess.AddClientGroup(clientGroup);
            return(Task.FromResult(clientGroup));
        }
 public static Task PutGroup(ClientGroupDto clientGroupDto, IRestClient client) =>
 CreateRequest(HttpVerb.Put, clientGroupDto.ClientGroupId, clientGroupDto).Execute(client);
 public static Task <ClientGroupDto> PostGroup(ClientGroupDto clientGroupDto, IRestClient client) =>
 CreateRequest(HttpVerb.Post, null, clientGroupDto).Execute(client).CreateFromLocationId(x =>
 {
     clientGroupDto.ClientGroupId = x;
     return(clientGroupDto);
 });