public async Task <IHttpActionResult> PutPhotoBuyHistory(int id, PhotoBuyHistory photoBuyHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != photoBuyHistory.Id) { return(BadRequest()); } db.Entry(photoBuyHistory).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhotoBuyHistoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetPhotoBuyHistory(int id) { PhotoBuyHistory photoBuyHistory = await db.PhotoBuyHistories.FindAsync(id); if (photoBuyHistory == null) { return(NotFound()); } return(Ok(photoBuyHistory)); }
public async Task <IHttpActionResult> DeletePhotoBuyHistory(int id) { PhotoBuyHistory photoBuyHistory = await db.PhotoBuyHistories.FindAsync(id); if (photoBuyHistory == null) { return(NotFound()); } db.PhotoBuyHistories.Remove(photoBuyHistory); await db.SaveChangesAsync(); return(Ok(photoBuyHistory)); }
public async Task <IHttpActionResult> PostPhotoBuyHistory(PhotoBuyHistoryBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var member = db.Members.Find(model.UserId); var photo = db.Photos.Find(model.PhotoId); if (photo == null) { // 구매사진 정보를 찾을 수 없습니다. var error = new HttpError(); error["ErrorCode"] = ErrorCode.PhotoSaveHistory_NoPhoto; error.Message = "구매사진정보를 찾을 수 없습니다."; HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, error); return(ResponseMessage(response)); } if (member.Wave < photo.Wave) { // 구매에 필요한 Wave가 부족합니다. var error = new HttpError(); error["ErrorCode"] = ErrorCode.PhotoSaveHistory_NoWave; error.Message = "구매에 필요한 Wave가 부족합니다."; HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, error); return(ResponseMessage(response)); } member.Wave = member.Wave - photo.Wave; var photoBuyHistory = new PhotoBuyHistory() { UserId = model.UserId, PhotoId = model.PhotoId, Wave = photo.Wave, Date = DateTime.Now, Paid = false, PaidDate = DateTime.Now }; db.PhotoBuyHistories.Add(photoBuyHistory); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = photoBuyHistory.Id }, photoBuyHistory)); }