Example #1
0
        public JsonResult Delete(string model)
        {
            if (!AuthorizationProvider.CanEditRevenue())
            {
                return(Forbidden());
            }

            // parameter is passed in as a model with Json string
            var entity        = JsonConvert.DeserializeObject <ResolutionRevenueModel>(model);
            var ownerPayoutId = entity.OwnerPayoutId;

            try
            {
                var dataProvider = new ResolutionRevenueProvider(_dbContext);
                dataProvider.Delete(entity.ResolutionId);
                dataProvider.Commit();

                var provider = new OwnerPayoutProvider(_dbContext);
                provider.UpdateOwnerPayoutMatchStatus(ownerPayoutId);

                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(InternalError(string.Format("Delete Resolution {0:d} fails.", entity.ResolutionId), "fail", ex));
            }
        }
Example #2
0
        public JsonResult DeleteRevenue(int id)
        {
            if (!AuthorizationProvider.CanEditRevenue())
            {
                return(Forbidden());
            }

            try
            {
                var dataProvider = new ResolutionRevenueProvider(_dbContext);
                var entity       = dataProvider.Retrieve(id);

                dataProvider.Delete(id);
                dataProvider.Commit();

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

                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                string message = string.Format("Delete Resolution {0} fails. {1}", id.ToString(), ex.Message + ex.StackTrace);
                return(InternalError(message, "fail", ex));
            }
        }
        public JsonResult SaveRevenue(OwnerPayoutRevenueModel form)
        {
            if (!AuthorizationProvider.CanEditRevenue())
            {
                string message = string.Format("User '{0}' does not have permission to save Owner Payout {1}.", this.User.Identity.Name, form.OwnerPayoutId.ToString());
                DojoLogger.Warn(message, typeof(OwnerPayoutController));
                Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden;
                return(Json(string.Empty, JsonRequestBehavior.AllowGet));
            }

            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);
                }

                var dataProvider = new OwnerPayoutRevenueProvider(_dbContext);

                if (form.OwnerPayoutId == 0) // new OwnerPayout
                {
                    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 OwnerPayout
                {
                    dataProvider.Update(form.OwnerPayoutId, form);
                }

                dataProvider.Commit(); // OwnerPayoutId will be filled for new OwnerPayout by EF

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

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

                return(Json(form.OwnerPayoutId.ToString(), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Saving Owner Payout {0} fails. {1},{2}", form.OwnerPayoutId.ToString(), ex.Message, innerErrorMessage);
                DojoLogger.Error(message, typeof(OwnerPayoutController));
                Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return(Json(string.Empty, JsonRequestBehavior.AllowGet));
            }
        }
Example #4
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));
            }
        }
Example #5
0
        public JsonResult ConvertRevenue(int id)
        {
            if (!AuthorizationProvider.CanEditRevenue())
            {
                return(Forbidden());
            }

            try
            {
                var reservationProvider = new ReservationRevenueProvider(_dbContext);
                var entity = reservationProvider.Retrieve(id);

                // create resolution entity
                var resolutionModel = new ResolutionRevenueModel();
                resolutionModel.ResolutionDate        = entity.PayoutDate;
                resolutionModel.OwnerPayoutId         = entity.OwnerPayoutId;
                resolutionModel.ConfirmationCode      = entity.ConfirmationCode;
                resolutionModel.PropertyCode          = entity.PropertyCode;
                resolutionModel.ResolutionType        = "Cancellation";
                resolutionModel.ResolutionDescription = "Converted from Reservation";
                resolutionModel.ResolutionAmount      = entity.TotalRevenue;
                resolutionModel.IncludeOnStatement    = true;
                resolutionModel.Impact         = string.Empty;
                resolutionModel.ApprovalStatus = RevenueApprovalStatus.NotStarted;

                var resolutionProvider = new ResolutionRevenueProvider(_dbContext);
                resolutionProvider.Create(resolutionModel);
                resolutionProvider.Commit();

                // set reservation revenue to 0 and excluded from statement
                entity.TotalRevenue       = 0;
                entity.IncludeOnStatement = false;
                reservationProvider.Update(id, entity);
                reservationProvider.Commit();

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

                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                string message = string.Format("Delete Reservation {0} fails. {1}", id.ToString(), ex.Message + ex.StackTrace);
                return(InternalError(message, "fail", ex));
            }
        }
Example #6
0
        public JsonResult SaveRevenue(ResolutionRevenueModel form)
        {
            if (!AuthorizationProvider.CanEditRevenue())
            {
                return(Forbidden());
            }

            try
            {
                // Impact list is defined in lookup table; Advance Payout does not have a confirmation code
                if (form.Impact == "Advance Payout")
                {
                    form.ConfirmationCode = string.Empty;
                }

                var dataProvider = new ResolutionRevenueProvider(_dbContext);
                if (form.ResolutionId == 0) // new
                {
                    dataProvider.Create(form);
                }
                else // update
                {
                    dataProvider.Update(form.ResolutionId, form);
                }

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

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

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

                return(Json(form.ResolutionId.ToString(), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Saving Resolution {0} fails. {1},{2}", form.ResolutionId.ToString(), ex.Message, innerErrorMessage);
                return(InternalError(message, string.Empty, ex));
            }
        }