Пример #1
0
        public ActionResult PricePush()
        {
            if (!AuthorizationProvider.CanEditPricing())
            {
                return(Forbidden());
            }

            try
            {
                var apiService = new FantasticService();
                var result     = apiService.PricePush(new FantasticPriceModel {
                    ListingId   = 1157,
                    StartDate   = new DateTime(2018, 12, 17),
                    EndDate     = new DateTime(2018, 12, 20),
                    IsAvailable = true,
                    Price       = 1150,
                    Note        = "Dojo Api call"
                });                                 // SD011
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(0, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        public ActionResult ViewPrices(int listingId, DateTime startDate, DateTime endDate)
        {
            if (!AuthorizationProvider.CanEditPricing())
            {
                return(Forbidden());
            }

            try
            {
                var apiService = new FantasticService();
                var result     = apiService.PriceListing(listingId, startDate, endDate);
                if (result.success)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var response = new { success = false, message = "There is error while calling Fantastic calendar API." };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                var result = new { success = false, message = ex.Message };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Пример #3
0
        public JsonResult SyncMap()
        {
            if (!AuthorizationProvider.IsStatementAdmin() && !AuthorizationProvider.IsPricingAdmin())
            {
                return(Forbidden());
            }

            try
            {
                var apiService  = new FantasticService();
                var listingJson = apiService.PropertyListing();
                if (listingJson.total > 0)
                {
                    int changeCount  = 0;
                    var dataProvider = new PropertyFantasticMapProvider(_dbContext);
                    foreach (var map in listingJson.listings)
                    {
                        changeCount += dataProvider.AddOrUpdate(map, false) == true ? 1: 0;
                    }

                    var sync    = 1;
                    var message = "Total of " + changeCount.ToString() + " listing IDs are updated.";
                    if (changeCount > 0)
                    {
                        dataProvider.Commit();
                    }
                    else
                    {
                        sync    = 2;
                        message = "Sync is completed. No change is needed.";
                    }
                    var result = new { sync = sync, message = message };
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var result = new { sync = 3, message = "No property is available from Fantastic API service." };
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                var result = new { sync = 0, message = ex.Message };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Пример #4
0
        public ActionResult PriceListing()
        {
            if (!AuthorizationProvider.CanEditPricing())
            {
                return(Forbidden());
            }

            try
            {
                var apiService = new FantasticService();
                var listing    = apiService.PriceListing(1157, new DateTime(2018, 12, 17), new DateTime(2018, 12, 20)); // SD011
                return(Json(listing, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(0, JsonRequestBehavior.AllowGet));
            }
        }
Пример #5
0
        public ActionResult PropertyListing()
        {
            if (!AuthorizationProvider.CanEditPricing())
            {
                return(Forbidden());
            }

            try
            {
                var apiService = new FantasticService();
                var listing    = apiService.PropertyListing();
                return(Json(listing, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(0, JsonRequestBehavior.AllowGet));
            }
        }
Пример #6
0
        public ActionResult UpdateCustomStays(AirbnbPricingViewModel form, HttpPostedFileBase attachedPricingFile)
        {
            if (!AuthorizationProvider.CanEditPricing())
            {
                return(Forbidden());
            }

            try
            {
                int    total = 0, good = 0, bad = 0;
                string message = string.Empty;
                if (attachedPricingFile != null)
                {
                    // parse out custom stay file for those that need to be updated
                    var provider = new AirbnbCustomStayProvider(_dbContext);
                    var models   = provider.ImportCustomStays(attachedPricingFile.InputStream);

                    // use Fantastic API service to update custom stay, returning the service result
                    var apiService = new FantasticService();
                    total = models.Count;
                    foreach (var model in models)
                    {
                        var response = apiService.CustomStayUpdate(model);
                        if (response.success == false)
                        {
                            bad++;
                            message = "Fantastic API call error: " + response.error;
                        }
                        else
                        {
                            good++;
                        }
                    }
                }

                var result = new { total = total, good = good, bad = bad, imported = 1, message = message };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var result = new { imported = 0, message = ex.Message };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Пример #7
0
        /// <summary>
        /// Filter price models to those that are not yet booked and have different prices
        /// </summary>
        /// <param name="orderedModels">list of price models sorted by listingId</param>
        /// <returns>the price models that need to be updated</returns>
        private List <FantasticPriceModel> FilterModels(List <FantasticPriceModel> orderedModels)
        {
            var apiService     = new FantasticService();
            var filteredModels = new List <FantasticPriceModel>();
            List <CalendarMap> priceCalendar = null;

            int currentListingId = 0;

            foreach (var model in orderedModels)
            {
                // query once for each unique listingId (models comes in as sorted order)
                if (currentListingId != model.ListingId)
                {
                    priceCalendar    = null;
                    currentListingId = model.ListingId;
                    // find the end date for same listingId
                    var endDateModel = orderedModels.Where(x => x.ListingId == currentListingId).OrderByDescending(x => x.EndDate).FirstOrDefault();
                    if (endDateModel != null)
                    {
                        var result = apiService.PriceListing(model.ListingId, model.StartDate, endDateModel.EndDate);
                        if (result.success == true)
                        {
                            priceCalendar = result.calendar;
                        }
                    }
                }

                if (priceCalendar != null)
                {
                    // only update those dates that are available with different prices
                    if (priceCalendar.Exists(x => x.fs_listing_id == model.ListingId.ToString() &&
                                             x.date == model.StartDate.ToString("yyyy-MM-dd") &&
                                             x.status == FantasticService.PRICING_AVAILABLE &&
                                             x.price != model.Price))
                    {
                        filteredModels.Add(new FantasticPriceModel(model));
                    }
                }
            }

            return(filteredModels);
        }
        private List <FantasticCustomStayModel> FilterModels(List <FantasticCustomStayModel> orderedModels)
        {
            var apiService     = new FantasticService();
            var filteredModels = new List <FantasticCustomStayModel>();
            List <CustomStayMap> customStayCalendar = null;

            int currentListingId = 0;

            foreach (var model in orderedModels)
            {
                // query once for each unique listingId (models comes in as sorted order)
                if (currentListingId != model.ListingId)
                {
                    customStayCalendar = null;
                    currentListingId   = model.ListingId;
                    // find the end date for same listingId
                    var endDateModel = orderedModels.Where(x => x.ListingId == currentListingId).OrderByDescending(x => x.EndDate).FirstOrDefault();
                    if (endDateModel != null)
                    {
                        var result = apiService.CustomStayListing(model.ListingId, model.StartDate, endDateModel.EndDate);
                        if (result.success == true)
                        {
                            customStayCalendar = result.calendar;
                        }
                    }
                }

                if (customStayCalendar != null)
                {
                    // only update those dates that are available with different custom stay
                    if (customStayCalendar.Exists(x => x.fs_listing_id == model.ListingId.ToString() &&
                                                  x.min_stay != model.MinStay))
                    {
                        filteredModels.Add(new FantasticCustomStayModel(model));
                    }
                }
            }

            return(filteredModels);
        }