public async Task DeleteGroup(GroupResponseDto groupDto) { var group = this.Mapper.Map <Group>(groupDto); this.Repository.Delete(group); await this.Repository.SaveAsync(); }
public async Task <ActionResult> UpdateGroup(Guid id, [FromBody] GroupRequestDto groupDto) { // Check if the group exists GroupResponseDto group = await GroupApplication.GetGroup(g => g.Id.Equals(id)); if (group == null) { ErrorMessage error = new ErrorMessage((int)HttpStatusCode.NotFound, $"O grupo, {id}, não foi encontrado."); return(NotFound(error)); } if (group.Name != groupDto.Name) { // Check if the group already exists GroupResponseDto groupByName = await GroupApplication.GetGroup((g) => g.Name.ToLower().Equals(groupDto.Name.ToLower())); if (groupByName != null) { ErrorMessage error = new ErrorMessage((int)HttpStatusCode.BadRequest, $"O grupo, {groupDto.Name}, já existe."); return(BadRequest(error)); } } await GroupApplication.UpdateGroup(id, groupDto); return(Ok()); }
public async Task <ActionResult <GroupResponseDto> > GetGroupById(Guid id) { GroupResponseDto groupDto = await GroupApplication.GetGroup(g => g.Id.Equals(id)); if (groupDto == null) { ErrorMessage error = new ErrorMessage((int)HttpStatusCode.NotFound, $"O grupo, {id}, não foi encontrado."); return(NotFound(error)); } return(Ok(groupDto)); }
protected override GroupResponseDto Convert(int key, int count) { var sex = _repo.SexData.GetValue((byte)key); var dto = new GroupResponseDto { Count = count, Sex = sex }; return(dto); }
protected override GroupResponseDto Convert(int key, int count) { var sortedCountryIndex = key; var country = _repo.CountryData.GetValueBySortedIndex((byte)sortedCountryIndex); var dto = new GroupResponseDto { Count = count, Country = country == string.Empty ? null : country }; return dto; }
protected override GroupResponseDto Convert(int key, int count) { var sortedInterestsIndex = key; var interest = _repo.InterestsData.GetValueBySortedIndex((short)sortedInterestsIndex); var dto = new GroupResponseDto { Count = count, Interests = interest }; return(dto); }
protected override GroupResponseDto Convert(int key, int count) { var sortedStatusIndex = key; var status = _repo.StatusData.GetValueBySortedIndex((byte)sortedStatusIndex); var dto = new GroupResponseDto { Count = count, Status = status }; return(dto); }
protected override GroupResponseDto Convert(int key, int count) { var sortedCityIndex = key; var city = _repo.CityData.GetValueBySortedIndex((short)sortedCityIndex); var dto = new GroupResponseDto { Count = count, City = city == string.Empty ? null : city }; return(dto); }
protected override GroupResponseDto Convert(int orderedKey, int count) { var sortedSexIndex = orderedKey % _minorCount; var sortedCityIndex = (orderedKey - sortedSexIndex) / _minorCount; var sex = _repo.SexData.GetValue((byte)sortedSexIndex); var city = _repo.CityData.GetValueBySortedIndex((short)sortedCityIndex); var dto = new GroupResponseDto { Count = count, Sex = sex, City = city == string.Empty ? null : city }; return(dto); }
protected override GroupResponseDto Convert(int orderedKey, int count) { var sortedStatusIndex = orderedKey % _minorCount; var sortedCountryIndex = (orderedKey - sortedStatusIndex) / _minorCount; var status = _repo.StatusData.GetValueBySortedIndex((byte)sortedStatusIndex); var country = _repo.CountryData.GetValueBySortedIndex((byte)sortedCountryIndex); var dto = new GroupResponseDto { Count = count, Status = status, Country = country == string.Empty ? null : country }; return(dto); }
public async Task <ActionResult> DeleteGroup(Guid id) { // Check if the group exists GroupResponseDto groupDto = await GroupApplication.GetGroup(r => r.Id.Equals(id)); GroupItemsResponseDto groupItemsDto = await GroupApplication.GetGroupItems(g => g.Id.Equals(id)); if (groupDto == null) { ErrorMessage error = new ErrorMessage((int)HttpStatusCode.NotFound, $"O grupo, {id}, não foi encontrado."); return(NotFound(error)); } if (groupItemsDto.Items != null && groupItemsDto.Items.Count() > 0) { ErrorMessage error = new ErrorMessage((int)HttpStatusCode.NotFound, $"O grupo não foi deletado. Existem itens associados ao grupo."); return(BadRequest(error)); } await GroupApplication.DeleteGroup(groupDto); return(NoContent()); }