Ejemplo n.º 1
0
        public async Task <(HttpStatusCode statusCode, CoffeeDto coffeeDto)> GetCoffeeByName(string coffeeName)
        {
            _logger.LogInformation($"Service-GetCoffeeByName-Executing GetCoffeeByName started at {DateTime.UtcNow}");

            coffeeName.CheckArgumentIsNull(nameof(coffeeName));

            var coffeeDto  = default(CoffeeDto);
            var statusCode = HttpStatusCode.NotFound;

            var coffeeSpec = new CoffeeWithAreasSpecification(coffeeName, false);

            var coffee = (await _coffeeRepository.ListAsync(coffeeSpec).ConfigureAwait(false)).FirstOrDefault();

            if (coffee == null)
            {
                _logger.LogInformation($"No coffee found with name  {coffeeName}");
            }
            else
            {
                statusCode = HttpStatusCode.OK;
                coffeeDto  = coffee.ToDto();
            }

            _logger.LogInformation($"Service-GetCoffeeByName-Executing GetCoffeeByName completed at {DateTime.UtcNow}");

            return(statusCode, coffeeDto);
        }
Ejemplo n.º 2
0
        public async Task <(HttpStatusCode statusCode, string coffeeId)> CreateCoffee(AddCoffeeDto coffeeToAdd)
        {
            _logger.LogInformation($"Service-CreateCoffee-Executing CreateCoffee started at {DateTime.UtcNow}");

            var       coffeeId      = string.Empty;
            var       statusCode    = HttpStatusCode.Created;
            CoffeeDto cofeeToStrore = default(CoffeeDto);

            var coffeeSpec = new CoffeeWithAreasSpecification(coffeeToAdd.CoffeeName, false);

            var cofee = (await _coffeeRepository.ListAsync(coffeeSpec).ConfigureAwait(false)).FirstOrDefault();

            if (cofee != null)
            {
                _logger.LogInformation($"cofee with cofee name {coffeeToAdd.CoffeeName} already exists!!!");
                statusCode = HttpStatusCode.BadRequest;
            }
            else
            {
                Coffee cofeeEntity = await _coffeeRepository.GetMaxOfPrimaryKey();

                string newCoffeeDisplayId = cofeeEntity.GetNextPrimaryKey();

                cofeeToStrore            = new CoffeeDto(newCoffeeDisplayId);
                cofeeToStrore.CoffeeName = coffeeToAdd.CoffeeName;

                await _coffeeRepository.AddAsync(cofeeToStrore.ToEntity(true)).ConfigureAwait(false);

                await _coffeeRepository.SaveAllwithAudit().ConfigureAwait(false);

                statusCode = HttpStatusCode.OK;
                coffeeId   = newCoffeeDisplayId;
            }

            _logger.LogInformation($"Service-CreateCoffee-Executing CreateCoffee completed at {DateTime.UtcNow}");

            return(statusCode, coffeeId);
        }
Ejemplo n.º 3
0
        public async Task <(HttpStatusCode statusCode, IEnumerable <CoffeeDto> coffeeDtos)> GetAllCoffees(bool includeCoffeeOwners)
        {
            _logger.LogInformation($"Service-GetAllCoffees-Executing GetAllCoffees started at {DateTime.UtcNow}");

            var coffeeDtos = default(IEnumerable <CoffeeDto>);
            var statusCode = HttpStatusCode.OK;

            var coffeeSpec = new CoffeeWithAreasSpecification(includeCoffeeOwners);

            var allCoffees = (await _coffeeRepository.ListAsync(coffeeSpec).ConfigureAwait(false));

            if (!allCoffees.Any())
            {
                _logger.LogInformation($"No coffees found");
            }
            else
            {
                coffeeDtos = allCoffees.ToDtos();
            }

            _logger.LogInformation($"Service-GetAllCoffees-Executing GetAllCoffees completed at {DateTime.UtcNow}");

            return(statusCode, coffeeDtos);
        }