public async Task<IHttpActionResult> PutBeautyShopReviewFile(int id, StoreReviewFile beautyShopReviewFile) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != beautyShopReviewFile.StoreReviewFileNo) { return BadRequest(); } db.Entry(beautyShopReviewFile).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BeautyShopReviewFileExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostBeautyShopReviewFile(StoreReviewFile beautyShopReviewFile) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.StoreReviewFiles.Add(beautyShopReviewFile); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = beautyShopReviewFile.StoreReviewFileNo }, beautyShopReviewFile); }
public async Task<IHttpActionResult> PostStoreReview() { PetterResultType<StoreReview> petterResultType = new PetterResultType<StoreReview>(); List<StoreReview> storeReviews = new List<StoreReview>(); List<StoreReviewFile> storeReviewFiles = new List<StoreReviewFile>(); StoreReview storeReview = new StoreReview(); if (Request.Content.IsMimeMultipartContent()) { string folder = HostingEnvironment.MapPath(UploadPath.StoreReviewPath); 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)) { StoreReviewFile storeReviewFile = new StoreReviewFile(); var file = await content.ReadAsByteArrayAsync(); string fileName = Utilities.additionFileName(content.Headers.ContentDisposition.FileName.Trim('"')); if (!FileExtension.StoreReviewExtensions.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.StoreReviewWidth, FileSize.StoreReviewHeight, ImageFormat.Png); storeReviewFile.FileName = fileName; storeReviewFile.FilePath = UploadPath.StoreReviewPath.Replace("~", ""); storeReviewFile.DateCreated = DateTime.Now; storeReviewFile.DateModified = DateTime.Now; storeReviewFile.StateFlag = StateFlags.Use; storeReviewFiles.Add(storeReviewFile); } else { string str = await content.ReadAsStringAsync(); string item = HttpUtility.UrlDecode(str); #region switch case switch (fieldName) { case "StoreNo": storeReview.StoreNo = int.Parse(item); break; case "MemberNo": storeReview.MemberNo = int.Parse(item); break; case "Content": storeReview.Content = item; break; case "Grade": storeReview.Grade = Convert.ToDouble(item); break; default: break; } #endregion switch case } } storeReview.StateFlag = StateFlags.Use; storeReview.DateCreated = DateTime.Now; storeReview.DateModified = DateTime.Now; // 스토어 리뷰 등록 db.StoreReviews.Add(storeReview); int num = await this.db.SaveChangesAsync(); // 스토어 리뷰 파일 등록 foreach (var item in storeReviewFiles) { item.StoreReviewNo = storeReview.StoreReviewNo; } db.StoreReviewFiles.AddRange(storeReviewFiles); int num1 = await this.db.SaveChangesAsync(); storeReviews.Add(storeReview); petterResultType.IsSuccessful = true; petterResultType.JsonDataSet = storeReviews; } else { petterResultType.IsSuccessful = false; petterResultType.JsonDataSet = null; } return Ok(petterResultType); }