public async Task <(HttpStatusCode statusCode, AreaDto areaDto)> GetAreaByName(string areaName) { _logger.LogInformation($"Service-GetAreaByName-Executing GetAreaByName started at {DateTime.UtcNow}"); areaName.CheckArgumentIsNull(nameof(areaName)); var areaDto = default(AreaDto); var statusCode = HttpStatusCode.NotFound; var areaSpec = new AreaWithAreaOwnersSpecification(areaName, false); var area = (await _areaRepository.ListAsync(areaSpec).ConfigureAwait(false)).FirstOrDefault(); if (area == null) { _logger.LogInformation($"No Area found for {areaName}"); } else { statusCode = HttpStatusCode.OK; areaDto = area.ToDto(); } _logger.LogInformation($"Service-GetAreaByName-Executing GetAreaByName completed at {DateTime.UtcNow}"); return(statusCode, areaDto); }
public async Task <(HttpStatusCode statusCode, string areaDisplayId)> CreateArea(AreaDto areaToAdd) { _logger.LogInformation($"Service-CreateArea-Executing CreateArea started at {DateTime.UtcNow}"); var areaDisplayId = string.Empty; var statusCode = HttpStatusCode.Created; var areaSpec = new AreaWithAreaOwnersSpecification(areaToAdd.AreaName, false); var area = (await _areaRepository.ListAsync(areaSpec).ConfigureAwait(false)).FirstOrDefault(); if (area != null) { _logger.LogInformation($"Area with area name {areaToAdd.AreaName} already exists!!!"); statusCode = HttpStatusCode.BadRequest; } else { Area areaEntity = await _areaRepository.GetMaxOfPrimaryKey(); areaToAdd.AreaDisplayId = areaEntity.GetNextPrimaryKey(); await _areaRepository.AddAsync(areaToAdd.ToEntity(true)).ConfigureAwait(false); await _areaRepository.SaveAllwithAudit().ConfigureAwait(false); statusCode = HttpStatusCode.OK; areaDisplayId = areaToAdd.AreaDisplayId; } _logger.LogInformation($"Service-GetAreaByName-Executing CreateArea completed at {DateTime.UtcNow}"); return(statusCode, areaDisplayId); }
public async Task <(HttpStatusCode statusCode, IEnumerable <AreaDto> areaDtos)> GetAllAreas(bool includeAreaOwners) { _logger.LogInformation($"Service-GetAllAreas-Executing GetAllAreas started at {DateTime.UtcNow}"); var areaDtos = default(IEnumerable <AreaDto>); var statusCode = HttpStatusCode.OK; var areaSpec = new AreaWithAreaOwnersSpecification(includeAreaOwners); var allAreas = (await _areaRepository.ListAsync(areaSpec).ConfigureAwait(false)); if (!allAreas.Any()) { _logger.LogInformation($"No Areas found"); } else { areaDtos = allAreas.ToDtos(); } _logger.LogInformation($"Service-GetAreaByName-Executing GetAllAreas completed at {DateTime.UtcNow}"); return(statusCode, areaDtos); }