public async Task <HttpResponseMessage> UploadSingleFile() { try { ItemResponse <int> response = new ItemResponse <int>(); HttpPostedFile postedFile = HttpContext.Current.Request.Files[0]; LogoAddRequest model = new LogoAddRequest { FileName = postedFile.FileName, Size = postedFile.ContentLength, ContentType = postedFile.ContentType, }; string contentType = Request.Content.Headers.ContentType.MediaType; ServerFileName = string.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(postedFile.FileName), Guid.NewGuid().ToString(), Path.GetExtension(postedFile.FileName)); model.ServerFileName = ServerFileName; await SavePostedFile(postedFile); response.Item = _logoService.Insert(model); return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public int Insert(LogoAddRequest model) { int FileId = 0; DataProvider.ExecuteNonQuery("dbo.FileStorage_Insert" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@FileName", model.FileName); paramCollection.AddWithValue("@Size", model.Size); paramCollection.AddWithValue("@ContentType", model.ContentType); paramCollection.AddWithValue("@SystemFileName", model.ServerFileName); SqlParameter idParameter = new SqlParameter("@FileId", System.Data.SqlDbType.Int); idParameter.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(idParameter); } , returnParameters : delegate(SqlParameterCollection param) { Int32.TryParse(param["@FileId"].Value.ToString(), out FileId); }); return(FileId); }