public ActionResult ConfirmReservation(long reservationID) { if (!Request.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } else { if (ModelState.IsValid) { //send a request on the main server and await for the response DTOHelper dtoHlp = new DTOHelper(); MyRemoteServices.AgentEndpointPortClient aepc = new MyRemoteServices.AgentEndpointPortClient(); MyRemoteServices.confirmReservationRequest crRequest = dtoHlp.GetConfirmReservationRequest(reservationID, ReservationStatus.CONFIRMED); MyRemoteServices.confirmReservationResponse crResponse = aepc.confirmReservation(crRequest); if (crResponse.responseWrapper.success) { //save localy using (var ctx = new ApplicationDbContext()) { Reservation res = ctx.Reservations.FirstOrDefault(x => x.Id == reservationID); res.ReservationStatus = ReservationStatus.CONFIRMED; ctx.SaveChanges(); } } else { //some error happened, retry TempData["error"] = crResponse.responseWrapper.message; return(RedirectToAction("MyReservations", "Agent")); } TempData["success"] = "Successfully confirmed the reservation"; return(RedirectToAction("MyReservations", "Agent")); } else { //invalid VM exception TempData["error"] = "Some form atributes are incorrect"; return(RedirectToAction("MyReservations", "Agent")); } } }
public MyRemoteServices.confirmReservationRequest GetConfirmReservationRequest(long reservationId, ReservationStatus rStatus) { using (var ctx = new ApplicationDbContext()) { long serverId = (long)ctx.Reservations.FirstOrDefault(x => x.Id == reservationId).MainServerId; MyRemoteServices.ReservationLite resData = new MyRemoteServices.ReservationLite { reservationMainServerId = serverId, reservationStatus = (MyRemoteServices.ReservationStatus)rStatus }; MyRemoteServices.confirmReservationRequest retObj = new MyRemoteServices.confirmReservationRequest { reservationLite = resData }; return(retObj); } }