예제 #1
0
        public ActionResult Index(int id = 0)
        {
            var model = new InquiryViewModel();

            // old Dojo logic gets all inquiries if id is not found. so emulate it here.
            model.InquiryId = id;
            if (id != 0)
            {
                InquiryProvider     inquiryProvider = new InquiryProvider(_dbContext);
                InquiriesValidation inquiry         = inquiryProvider.Retrieve(id);
                if (inquiry == null)
                {
                    model.InquiryId = 0;
                }
            }

            model.UserName = this.User.Identity.Name;
            // hack here: for admin role, we set the UserName to 'DelegateDeletion' to allow admin to delete other's inquiry
            if (AuthorizationProvider.IsAdmin())
            {
                model.UserName = "******";
            }

            return(View(model));
        }
예제 #2
0
        public PartialViewResult Approve(InquiriesValidation form)
        {
            try
            {
                InquiryProvider  inquiryProvider  = new InquiryProvider(_dbContext);
                PropertyProvider propertyProvider = new PropertyProvider(_dbContext);

                InquiriesValidation inquiry = inquiryProvider.Retrieve(form.Id);
                form.CPL = propertyProvider.Retrieve(inquiry.PropertyCode);
                inquiry.Doesitrequire2pricingteamapprovals = form.Doesitrequire2pricingteamapprovals;
                inquiry.PricingApprover1 = form.PricingApprover1;
                inquiry.PricingApprover2 = form.PricingApprover2;
                inquiry.PricingDecision1 = form.PricingDecision1;
                inquiry.PricingReason1   = form.PricingReason1;
                inquiry.ApprovedbyOwner  = form.ApprovedbyOwner;

                inquiryProvider.Update(inquiry.Id, inquiry);
                inquiryProvider.Commit();
            }
            catch (Exception ex)
            {
                // TODO: Log error
                this.ModelState.AddModelError("", ex);
            }

            return(PartialView("ApprovePartial", form));
        }
예제 #3
0
        public JsonResult SaveApproveStatus(InquiriesValidation form)
        {
            if (!AuthorizationProvider.IsInquiryEditor())
            {
                string message = string.Format("User '{0}' does not have permission to save approval status for Inquiry {1}.", this.User.Identity.Name, form.Id.ToString());
                DojoLogger.Warn(message, typeof(InquiryController));

                return(Json("denied", JsonRequestBehavior.AllowGet));
            }

            try
            {
                InquiryProvider     inquiryProvider = new InquiryProvider(_dbContext);
                InquiriesValidation inquiry         = inquiryProvider.Retrieve(form.Id);
                SetApproveFields(inquiry, form);
                inquiryProvider.Update(inquiry.Id, inquiry);
                inquiryProvider.Commit();

                return(Json(form.Id.ToString(), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                string message = string.Format("Save Apporval Ststus for Inquiry {0} fails. {1}", form.Id.ToString(), ex.Message + ex.StackTrace);
                DojoLogger.Error(message, typeof(InquiryController));
            }
            return(Json(string.Empty, JsonRequestBehavior.AllowGet));
        }
예제 #4
0
        public ActionResult Edit(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
            {
                ViewBag.Title      = "Edit Inquiry";
                ViewBag.ButtonText = "Update Inquiry";

                InquiryProvider     inquiryProvider  = new InquiryProvider(_dbContext);
                PropertyProvider    propertyProvider = new PropertyProvider(_dbContext);
                InquiriesValidation inquiry          = inquiryProvider.Retrieve(Id);
                if (inquiry == null)
                {
                    return(RedirectToAction("NotFound", "Error"));
                }
                ViewBag.Properties = propertyProvider.AggregatedProperties();
                return(PartialView("EditPartial", inquiry));
            }
            catch (Exception ex)
            {
                string message = string.Format("Retrieve Inquiry {0} for Editing fails. {1}", Id.ToString(), ex.Message + ex.StackTrace);
                DojoLogger.Error(message, typeof(InquiryController));
            }

            return(RedirectToAction("Index", "Inquiry")
                   .WithError("The inquiry item cannot be found."));
        }
예제 #5
0
        public JsonResult RetrieveInquiries(DateTime beginDate, DateTime endDate)
        {
            InquiryProvider dataProvider = new InquiryProvider(_dbContext);
            var             Inquiries    = dataProvider.Retrieve(beginDate, endDate);

            return(Json(Inquiries, JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        public JsonResult Retrieve(DateTime beginDate, DateTime endDate)
        {
            if (!AuthorizationProvider.IsViewer())
            {
                return(Json(string.Empty, JsonRequestBehavior.AllowGet));
            }

            InquiryProvider dataProvider = new InquiryProvider(_dbContext);
            var             inquiries    = dataProvider.Retrieve(beginDate, endDate);

            return(Json(inquiries, JsonRequestBehavior.AllowGet));
        }
예제 #7
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()));
        }
예제 #8
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."));
        }
예제 #9
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));
            }
        }