Пример #1
0
        public JsonResult Update(string model) // parameter must be the same json object defined in parameterMap in kendo's datab source
        {
            if (!AuthorizationProvider.IsStatementAdmin() && !AuthorizationProvider.IsPricingAdmin())
            {
                return(Forbidden());
            }

            var dataModel = JsonConvert.DeserializeObject <PropertyFantasticMap>(model);

            try
            {
                var dataProvider = new PropertyFantasticMapProvider(_dbContext);
                var entity       = dataProvider.Retrieve(dataModel.PropertyFantasticMapId);
                entity.PropertyCode = dataModel.PropertyCode;
                entity.ListingId    = dataModel.ListingId;
                dataProvider.Update(entity.PropertyFantasticMapId, entity);
                dataProvider.Commit();

                return(Json(dataModel, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Saving Property Fantastic Map {0:d} fails. {1} - {2}", dataModel.PropertyFantasticMapId, ex.Message, innerErrorMessage);
                return(InternalError(message, "fail", ex));
            }
        }
Пример #2
0
        public JsonResult Create(string model)
        {
            if (!AuthorizationProvider.IsStatementAdmin() && !AuthorizationProvider.IsPricingAdmin())
            {
                return(Forbidden());
            }

            var dataModel = JsonConvert.DeserializeObject <PropertyFantasticMap>(model);

            try
            {
                var map          = new PropertyFantasticMap();
                var dataProvider = new PropertyFantasticMapProvider(_dbContext);
                map.PropertyCode = dataModel.PropertyCode;
                map.ListingId    = dataModel.ListingId;
                dataProvider.Create(map);
                dataProvider.Commit();

                return(Json(dataModel, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Creating Property Fantastic Map fails. {0} - {1}", ex.Message, innerErrorMessage);
                return(InternalError(message, string.Empty));
            }
        }
Пример #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 JsonResult Retrieve()
        {
            if (!AuthorizationProvider.IsStatementAdmin() && !AuthorizationProvider.IsPricingAdmin())
            {
                return(Forbidden());
            }

            try
            {
                var provider = new PropertyFantasticMapProvider(_dbContext);
                var data     = provider.All();
                return(Json(data, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Retrieve Property Title fails. {0} - {1}", ex.Message, innerErrorMessage);
                return(InternalError(message, string.Empty));
            }
        }
Пример #5
0
        public JsonResult Delete(string model)
        {
            if (!AuthorizationProvider.IsStatementAdmin() && !AuthorizationProvider.IsPricingAdmin())
            {
                return(Forbidden());
            }

            var dataModel = JsonConvert.DeserializeObject <PropertyFantasticMap>(model);

            try
            {
                var dataProvider = new PropertyFantasticMapProvider(_dbContext);
                dataProvider.Delete(dataModel.PropertyFantasticMapId);
                dataProvider.Commit();
                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(InternalError(string.Format("Delete Property Fantastic Map {0:d} fails.", dataModel.PropertyFantasticMapId), "fail", ex));
            }
        }