Пример #1
0
        public async Task <IHttpActionResult> Get(int avatarId)
        {
            try
            {
                if (avatarId == 0)
                {
                    return(BadRequest($"Avatar id {avatarId} is not valid"));
                }
                var avatar = await _avatarRepository.Get(avatarId);

                if (avatar == null)
                {
                    return(BadRequest("Avatar not found"));
                }
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(avatar.Image)
                };
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");
                var response = ResponseMessage(result);
                return(response);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
#if DEBUG
                return(InternalServerError(e));
#else
                return(InternalServerError());
#endif
            }
        }