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); } }
private string GetPath(FileData file) { return HttpContext.Current.Server.MapPath(ValuesApp.ConvertImageNameToAbsolutePath(file.FileName)); }