public async Task <HttpResponseMessage> UpdateGroup(Guid id, string name, float?capacity)
        {
            PatchGroupResource saveGroupResource = new PatchGroupResource()
            {
                Name     = name,
                Capacity = capacity
            };

            return(await Client.PatchAsync($"{GroupApiUrl}{id.ToString()}", ConvertToJsonData <PatchGroupResource>(saveGroupResource)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Patch(Guid id, [FromBody] PatchGroupResource value)
        {
            Group group = await _context.Group.Include(g => g.ChargeStations).ThenInclude(c => c.Connectors).FirstOrDefaultAsync(g => g.Id == id);

            if (group == null)
            {
                return(StatusCode(404));
            }

            if (value.Capacity.HasValue)
            {
                if (value.Capacity.Value < group.Capacity && group.HasExceededCapacity(group.Capacity - value.Capacity.Value))
                {
                    List <Connector> connectors        = (List <Connector>)_context.Connector.Where(c => c.ChargeStation.GroupId == id).OrderBy(o => o.MaxCurrentAmp);
                    float            excdeededCapacity = group.GetExceededCapacity();


                    RemoveSuggestions removeSuggestions = new RemoveSuggestions();
                    removeSuggestions.GenerateAllSuggestions(connectors, excdeededCapacity);
                    throw new CapacityExceededException(excdeededCapacity, removeSuggestions);
                }

                group.Capacity = value.Capacity.Value;
            }

            if (!string.IsNullOrEmpty(value.Name))
            {
                group.Name = value.Name;
            }

            await _context.SaveChangesAsync();

            GroupResource updatedGroup = _mapper.Map <GroupResource>(group);

            return(Ok(updatedGroup));
        }