Exemplo n.º 1
0
        public async Task<HttpResponseMessage> AddImage(int id, FileData file)
        {

            try
            {
                var path = GetPath(file);
                var img = await _imageService.AddImageAsync(id, file.Data, path);
                return Request.CreateResponse(HttpStatusCode.Created, img.ImagePath);

            }
            catch (ArgumentException e)
            {
                var msg = string.Format("Photo by id - {0} has been failed save, name is incorrect", id);
                _log.LogWriteInfo(msg);
                return Request.CreateResponse(HttpStatusCode.BadRequest, msg);
            }
            catch (Exception e)
            {
                _log.LogWriteError(string.Format("photo by id - {0} has been failed", id), e);
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

        }
Exemplo n.º 2
0
 private string GetPath(FileData file)
 {
     return HttpContext.Current.Server.MapPath(ValuesApp.ConvertImageNameToAbsolutePath(file.FileName));
 }