public async Task<IHttpActionResult> PutBoardFile(int id, BoardFile BoardFile) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != BoardFile.BoardFileNo) { return BadRequest(); } db.Entry(BoardFile).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BoardFileExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostBoardFile(BoardFile BoardFile) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.BoardFiles.Add(BoardFile); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = BoardFile.BoardFileNo }, BoardFile); }
public async Task<IHttpActionResult> PostBoard() { PetterResultType<Board> petterResultType = new PetterResultType<Board>(); List<Board> list = new List<Board>(); List<BoardFile> boardFiles = new List<BoardFile>(); Board board = new Board(); if (Request.Content.IsMimeMultipartContent()) { string folder = HostingEnvironment.MapPath(UploadPath.BoardPath); Utilities.CreateDirectory(folder); var provider = await Request.Content.ReadAsMultipartAsync(); foreach (var content in provider.Contents) { string fieldName = content.Headers.ContentDisposition.Name.Trim('"'); if (!string.IsNullOrEmpty(content.Headers.ContentDisposition.FileName)) { BoardFile boardFile = new BoardFile(); var file = await content.ReadAsByteArrayAsync(); string oldFileName = HttpUtility.UrlDecode(content.Headers.ContentDisposition.FileName.Trim('"')); string fileName = Utilities.additionFileName(oldFileName); if (!FileExtension.BoardExtensions.Any(x => x.Equals(Path.GetExtension(fileName.ToLower()), StringComparison.OrdinalIgnoreCase))) { petterResultType.IsSuccessful = false; petterResultType.JsonDataSet = null; petterResultType.ErrorMessage = ResultErrorMessage.FileTypeError; return Ok(petterResultType); } string fullPath = Path.Combine(folder, fileName); File.WriteAllBytes(fullPath, file); string thumbnamil = Path.GetFileNameWithoutExtension(fileName) + "_thumbnail" + Path.GetExtension(fileName); Utilities.ResizeImage(fullPath, thumbnamil, FileSize.BoardWidth, FileSize.BoardHeight, ImageFormat.Png); // 소식 대표 이미지 if (fieldName == FieldName.BoardFieldName) { board.FileName = fileName; board.FilePath = UploadPath.BoardPath.Replace("~", ""); } boardFile.FileName = fileName; boardFile.FilePath = UploadPath.BoardPath.Replace("~", ""); boardFile.DateCreated = DateTime.Now; boardFile.DateModified = DateTime.Now; boardFile.StateFlag = StateFlags.Use; boardFiles.Add(boardFile); } else { string str = await content.ReadAsStringAsync(); string item = HttpUtility.UrlDecode(str); #region switch case switch (fieldName) { case "StoreNo": board.StoreNo = int.Parse(item); break; case "CodeID": board.CodeID = item; break; case "MemberID": board.MemberID = item; break; case "Title": board.Title = item; break; case "Content": board.Content = item; break; default: break; } #endregion switch case } } board.StateFlag = StateFlags.Use; board.DateCreated = DateTime.Now; board.DateModified = DateTime.Now; // 게시판 등록 db.Boards.Add(board); int num = await this.db.SaveChangesAsync(); // 게시판 파일 등록 foreach (var item in boardFiles) { item.BoardNo = board.BoardNo; } db.BoardFiles.AddRange(boardFiles); int num1 = await this.db.SaveChangesAsync(); list.Add(board); petterResultType.IsSuccessful = true; petterResultType.JsonDataSet = list; } else { petterResultType.IsSuccessful = false; petterResultType.JsonDataSet = null; } return Ok(petterResultType); }