Ejemplo n.º 1
0
 private void SetRelatedFields(ReservationRevenueModel form)
 {
     // these are fields that initialized by app internally
     //form.OwnerPayoutId = 0;
     form.ApprovalStatus = (int)RevenueApprovalStatus.NotStarted;
     form.Reviewed       = false;
     form.Approved       = false;
     form.Finalized      = false;
 }
Ejemplo n.º 2
0
        public JsonResult SaveRevenue(ReservationRevenueModel form)
        {
            if (!AuthorizationProvider.CanEditRevenue())
            {
                return(Forbidden());
            }

            try
            {
                // treat checkin and checkout date as Hawaii time zone and covert it to UTC by adding 11 hours.
                if (form.PayoutDate != null)
                {
                    form.PayoutDate = ConversionHelper.ToUtcFromUs(form.PayoutDate.Value);
                }
                if (form.CheckinDate != null)
                {
                    form.CheckinDate = ConversionHelper.ToUtcFromUs(form.CheckinDate.Value);
                }

                var dataProvider = new ReservationRevenueProvider(_dbContext);
                if (form.ReservationId == 0) // new reservation
                {
                    if (dataProvider.GetKey(form) != 0)
                    {
                        Response.StatusCode = (int)System.Net.HttpStatusCode.Conflict; // code = 409
                        return(Json(string.Empty, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        dataProvider.Create(form);
                    }
                }
                else // updating reservation
                {
                    dataProvider.Update(form.ReservationId, form);
                }

                dataProvider.Commit(); // ReservationId will be filled for new reservation by EF

                // get the reservation ID
                if (form.ReservationId == 0)
                {
                    form.ReservationId = dataProvider.GetKey(form);
                }

                var provider = new OwnerPayoutProvider(_dbContext);
                provider.UpdateOwnerPayoutMatchStatus(form.OwnerPayoutId);

                return(Json(form.ReservationId.ToString(), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Saving Reservation {0} fails. {1},{2}", form.ReservationId.ToString(), ex.Message, innerErrorMessage);
                return(InternalError(message, string.Empty, ex));
            }
        }
Ejemplo n.º 3
0
        public ActionResult AddReservation(int Id)
        {
            var model = new ReservationRevenueModel();

            model.OwnerPayoutId = Id;
            model.ReservationId = 0;
            model.PropertyCode  = string.Empty;
            model.InputSource   = "system";
            return(PartialView("_NewReservationPartial", model));
        }
Ejemplo n.º 4
0
        public JsonResult SaveReservation(ReservationRevenueModel form)
        {
            // delegate to reservation controller service to save
            var delegatedController = DependencyResolver.Current.GetService <ReservationController>();

            delegatedController.ControllerContext = ControllerContext;
            var result = delegatedController.SaveRevenue(form);

            // return the owner payout Id instead of reservation Id
            try
            {
                int id = int.Parse(result.Data.ToString());
                return(Json(form.OwnerPayoutId.ToString(), JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(result);
            }
        }
Ejemplo n.º 5
0
        public ActionResult OwnerPayoutView(DateTime month, string source, int ownerPayoutId)
        {
            if (!AuthorizationProvider.CanViewRevenue())
            {
                return(Forbidden());
            }

            ViewBag.ReviewerClass  = AuthorizationProvider.CanReviewRevenue() ? "revenue-grid-reviewer" : string.Empty;
            ViewBag.ApproverClass  = AuthorizationProvider.CanApproveRevenue() ? "revenue-grid-approver" : string.Empty;
            ViewBag.FinalizerClass = AuthorizationProvider.CanFinalizeRevenue() ? "revenue-grid-finalizer" : string.Empty;
            ViewBag.EditClass      = AuthorizationProvider.CanEditRevenue() ? string.Empty : " revenue-field-readonly";
            ViewBag.AdminClass     = AuthorizationProvider.IsRevenueAdmin() ? "revenue-grid-remover" : string.Empty;

            var model = new ReservationRevenueModel();

            model.Month         = month;
            model.Source        = source;
            model.OwnerPayoutId = ownerPayoutId;

            return(View(model));
        }
Ejemplo n.º 6
0
        public ActionResult DetailInfo(int id)
        {
            if (!AuthorizationProvider.CanViewRevenue())
            {
                return(Forbidden());
            }

            ViewBag.EditClass = " app-field-readonly";
            var details = new ReservationRevenueModel();

            try
            {
                var provider = new ReservationRevenueProvider(_dbContext);

                ViewBag.Title = "View Reservation Details";
                details       = provider.Retrieve(id);
                if (details == null)
                {
                    details = new ReservationRevenueModel();
                }
                // append property code to confirmation code for view-only mode
                if (!string.IsNullOrEmpty(details.PropertyCode))
                {
                    if (string.IsNullOrEmpty(details.ConfirmationCode))
                    {
                        details.ConfirmationCode = string.Empty;
                    }
                    details.ConfirmationCode += " | " + details.PropertyCode;
                }

                return(PartialView("_ReservationEditPartial", details));
            }
            catch (Exception ex)
            {
                string message = string.Format("Retrieve Reservation Details fails. {0}", ex.Message);
                DojoLogger.Error(message, typeof(PropertyController));
            }

            return(PartialView("_ReservationEditPartial", details));
        }