Пример #1
0
        public async Task <IActionResult> GetById(Guid?id)
        {
            if (!id.HasValue)
            {
                Logger.LogWarning("Wrong identifier!");

                return(BadRequest());
            }

            OperationEntity entity = null;

            Byte[] result = await Cache.GetAsync($"operation-{id}");

            if ((result?.Length ?? 0) > 0)
            {
                entity = EntityExtensions.GetEntity <OperationEntity>(result);
            }
            else
            {
                entity = await Context.Operations.FirstOrDefaultAsync(o => o.Id == id.Value);

                if (entity != null)
                {
                    await Cache.SetAsync($"operation-{id}", entity.ToByteArray());
                }
            }

            if (entity == null)
            {
                Logger.LogWarning($"Entity with id: '{id.Value}' does not exists!");

                return(NotFound());
            }

            return(new ObjectResult(Mapper.Map <OperationModel>(entity)));
        }