Ejemplo n.º 1
0
        public ActionResult Approve(int Id)
        {
            if (!AuthorizationProvider.IsInquiryEditor() && !AuthorizationProvider.IsViewer())
            {
                string message = string.Format("User '{0}' does not have permission to edit Inquiry {1}.", this.User.Identity.Name, Id.ToString());
                DojoLogger.Warn(message, typeof(InquiryController));

                return(RedirectToAction("Index", "Inquiry")
                       .WithError("It looks like you do not have permisssion to edit this inquiry."));
            }

            try
            {
                InquiryProvider inquiryProvider = new InquiryProvider(_dbContext);

                ViewBag.Title      = "Approve Inquiry";
                ViewBag.ButtonText = "Approve Inquiry";
                InquiriesValidation inquiry = inquiryProvider.Retrieve(Id);
                if (inquiry == null)
                {
                    return(RedirectToAction("NotFound", "Error"));
                }

                // get the owner approval flag (string constant defined in ListProvider)
                inquiry.OwnerApprovalNeeded = (inquiry.CPL.NeedsOwnerApproval != null && inquiry.CPL.NeedsOwnerApproval.Value)
                                              ? (inquiry.CPL.NeedsOwnerApproval.Value ? "YES" : "NO")
                                              : "N/A";
                if (inquiry.PricingApprover1 == null)
                {
                    inquiry.PricingApprover1 = ViewBag.UserName;
                }
                if (inquiry.PricingApprover2 == null)
                {
                    inquiry.PricingApprover2 = ViewBag.UserName;
                }
                if (inquiry.PricingDecision1 == null)
                {
                    inquiry.PricingDecision1 = string.Empty;
                }

                return(PartialView("ApprovePartial", inquiry));
            }
            catch (Exception ex)
            {
                string message = string.Format("Retrieve Inquiry {0} for Approval fails. {1}", Id.ToString(), ex.Message + ex.StackTrace);
                DojoLogger.Error(message, typeof(InquiryController));
            }

            return(PartialView("ApprovePartial", new InquiriesValidation()));
        }
Ejemplo n.º 2
0
        public PartialViewResult Edit(InquiriesValidation form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    InquiryProvider inquiryProvider = new InquiryProvider(_dbContext);
                    inquiryProvider.Update(form.Id, form);
                    inquiryProvider.Commit();
                }
            }
            catch (Exception ex)
            {
                // TODO: Log error
                this.ModelState.AddModelError("", ex);
            }

            ViewBag.Accounts   = (new AirbnbAccountProvider(_dbContext)).AggregatedAccounts();
            ViewBag.Properties = (new PropertyProvider(_dbContext)).AggregatedProperties();
            return(PartialView("EditPartial", form));
        }
Ejemplo n.º 3
0
        public ActionResult Property(int Id)
        {
            if (!AuthorizationProvider.IsViewer())
            {
                return(PartialView("PropertyPartial", new InquiriesValidation()));
            }

            try
            {
                InquiryProvider  inquiryProvider  = new InquiryProvider(_dbContext);
                PropertyProvider propertyProvider = new PropertyProvider(_dbContext);

                ViewBag.Title = "View Property Information";
                InquiriesValidation inquiry = inquiryProvider.Retrieve(Id);
                if (inquiry == null)
                {
                    string message = string.Format("Inquiry {0} not found.", Id.ToString());
                    DojoLogger.Warn(message, typeof(InquiryController));

                    return(RedirectToAction("NotFound", "Error"));
                }

                // make up Airbnb property link if it does not already exist
                if (string.IsNullOrEmpty(inquiry.CPL.AirBnb) && !string.IsNullOrEmpty(inquiry.CPL.AIrBnBID))
                {
                    inquiry.CPL.AirBnb = string.Format(AppConstants.AIRBNB_URL_TEMPLATE, inquiry.CPL.AIrBnBID);
                }

                return(PartialView("PropertyPartial", inquiry));
            }
            catch (Exception ex)
            {
                string message = string.Format("Retrieve Inquiry Property Info fails. {0}", ex.Message);
                DojoLogger.Error(message, typeof(InquiryController));
            }

            return(RedirectToAction("Index", "Inquiry")
                   .WithError("The inquiry item cannot be found."));
        }
Ejemplo n.º 4
0
        public JsonResult Save(InquiriesValidation form)
        {
            if (!AuthorizationProvider.IsInquiryEditor())
            {
                string message = string.Format("User '{0}' does not have permission to save Inquiry {1}.", this.User.Identity.Name, form.Id.ToString());
                DojoLogger.Warn(message, typeof(InquiryController));
                return(Json("denied", JsonRequestBehavior.AllowGet));
            }

            try
            {
                // treat checkin and checkout date as Hawaii time zone and covert it to UTC by adding 11 hours.
                if (form.Check_inDate != null)
                {
                    form.Check_inDate = form.Check_inDate.Value.Date.AddHours(11);
                }
                if (form.Check_outDate != null)
                {
                    form.Check_outDate = form.Check_outDate.Value.Date.AddHours(11);
                }

                InquiryProvider inquiryProvider = new InquiryProvider(_dbContext);

                string message = string.Format("saving inquiry: name: {0} team: {1} property: {2} checkin: {3} checkout: {4} payout: {5}",
                                               form.GuestName,
                                               form.InquiryTeam,
                                               (!string.IsNullOrEmpty(form.PropertyCode) ? form.PropertyCode : "Invalid"),
                                               (form.Check_inDate != null ? form.Check_inDate.Value.ToShortDateString() : "Invalid"),
                                               (form.Check_outDate != null ? form.Check_outDate.Value.ToShortDateString() : "Invalid"),
                                               (form.TotalPayout != null ? form.TotalPayout.Value.ToString() : "Invalid"));
                DojoLogger.Trace(message, typeof(InquiryController));

                if (form.Id == 0) // new inquiry
                {
                    if (inquiryProvider.Exist(form.PropertyCode, form.GuestName, form.Check_inDate.Value, form.Check_outDate.Value))
                    {
                        Response.StatusCode = (int)System.Net.HttpStatusCode.Conflict; // code = 409
                        return(Json(string.Empty, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        SetRelatedFields(form);
                        inquiryProvider.Create(form);
                    }
                }
                else // updating inquiry
                {
                    InquiriesValidation inquiry = inquiryProvider.Retrieve(form.Id);
                    SetRelatedFields(inquiry, form);
                    // need to set CreatedBy and CreatedDate a they are not part of form
                    form.CreatedDate = inquiry.CreatedDate;
                    form.CreatedBy   = inquiry.CreatedBy;
                    inquiryProvider.Update(inquiry.Id, inquiry);
                }

                inquiryProvider.Commit(); // Id will be filled for new inquiry by EF

                PropertyProvider propertyProvider = new PropertyProvider(_dbContext);
                ViewBag.Properties = propertyProvider.AggregatedProperties();
                return(Json(form.Id.ToString(), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                string message = string.Format("Saving Inquiry {0} fails. {1}", form.Id.ToString(), ex.Message);
                DojoLogger.Error(message, typeof(InquiryController));
                Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return(Json(string.Empty, JsonRequestBehavior.AllowGet));
            }
        }