public IActionResult Create(CreateFeedbackVM vm) { if (ModelState.IsValid) { Booking booking = _bookingRepo.GetSingle(b => b.BookingId == vm.BookingId); if (booking != null && !booking.LeftFeedback) { var userId = _userManager.GetUserId(User); Feedback newFeedback = new Feedback { UserName = User.Identity.Name, TravelPackageId = vm.TravelPackageId, MyUserId = userId, Comment = vm.Comment }; _feedbackManager.Create(newFeedback); booking.LeftFeedback = true; _bookingRepo.Update(booking); return(RedirectToAction("Display", "TravelPackage", new { id = newFeedback.TravelPackageId })); } else { return(RedirectToAction("AccessDenied", "Account")); } } return(View()); }
public async Task <FeedbackVM> CreateFeedbackAsync(CreateFeedbackVM f) { var dbFeedback = new Feedback { Stars = f.Stars, Comment = f.Comment, UserProfileId = f.UserProfileId }; if (f.LocationId != null) { dbFeedback.LocationId = f.LocationId; } if (f.MenuItemId != null) { dbFeedback.MenuItemId = f.MenuItemId; } var newFeedback = await _db.Feedbacks.CreateAsync(dbFeedback); var f2 = _db.Feedbacks.GetAll().FirstOrDefault(m => m.Id == newFeedback.Id); if (f2 != null) { var retFeedback = new FeedbackVM(f2, f2.UserProfile, f2.Photos); if (f.UploadPhoto != null) { await _fileService.CreateFileDbAsync(f.UploadPhoto, retFeedback.Id); } return(retFeedback); } throw new Exception("feedback not found"); }
public async Task <IActionResult> CreateFeedback([FromForm] CreateFeedbackVM feedback) { try { if (feedback == null) { throw new Exception("Feedback is missing"); } feedback.UploadPhoto = HttpContext.Request.Form.Files[0]; var feedbackPage = await _feedbackService.CreateFeedbackAsync(feedback); return(Ok(feedbackPage)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult Create(int id) { Booking booking = _bookingRepo.GetSingle(t => t.BookingId == id); //add check for security if (booking != null && !booking.LeftFeedback) { if (booking.UserId == _userManager.GetUserId(User)) { CreateFeedbackVM vm = new CreateFeedbackVM { TravelPackageId = booking.PackageId, BookingId = booking.BookingId }; return(View(vm)); } } return(RedirectToAction("AccessDenied", "Account")); }