Ejemplo n.º 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())
            {
                return(Forbidden());
            }

            var feeModel = JsonConvert.DeserializeObject <PropertyFeeViewModel>(model);

            try
            {
                var dataProvider = new PropertyFeeProvider(_dbContext);
                var entity       = dataProvider.Retrieve(feeModel.PropertyFeeId);
                dataProvider.MapData(feeModel, ref entity);
                dataProvider.Update(entity.PropertyCostId, entity);
                dataProvider.Commit();

                return(Json(feeModel, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Saving Property Fee {0:d} fails. {1} - {2}", feeModel.PropertyFeeId, ex.Message, innerErrorMessage);
                return(InternalError(message, "fail", ex));
            }
        }
Ejemplo n.º 2
0
        public JsonResult Create(string model)
        {
            if (!AuthorizationProvider.IsStatementAdmin())
            {
                return(Forbidden());
            }

            var feeModel = JsonConvert.DeserializeObject <PropertyFeeViewModel>(model);

            try
            {
                var entity       = new PropertyFee();
                var dataProvider = new PropertyFeeProvider(_dbContext);
                dataProvider.MapData(feeModel, ref entity);
                dataProvider.Create(entity);
                dataProvider.Commit();

                feeModel.PropertyFeeId = entity.PropertyCostId; // set the created Id to return to kendo grid

                return(Json(feeModel, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Creating Property Fee fails. {0} - {1}", ex.Message, innerErrorMessage);
                return(InternalError(message, string.Empty));
            }
        }
Ejemplo n.º 3
0
        public JsonResult Retrieve()
        {
            if (!AuthorizationProvider.IsStatementAdmin())
            {
                return(Forbidden());
            }

            try
            {
                var provider     = new PropertyFeeProvider(_dbContext);
                var propertyFees = provider.All();
                return(Json(propertyFees, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Retrieve Property Fee fails. {0} - {1}", ex.Message, innerErrorMessage);
                return(InternalError(message, string.Empty));
            }
        }
Ejemplo n.º 4
0
        public JsonResult Delete(string model)
        {
            if (!AuthorizationProvider.IsStatementAdmin())
            {
                return(Forbidden());
            }

            var feeModel = JsonConvert.DeserializeObject <PropertyFeeViewModel>(model);

            try
            {
                var dataProvider = new PropertyFeeProvider(_dbContext);
                dataProvider.Delete(feeModel.PropertyFeeId);
                dataProvider.Commit();
                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(InternalError(string.Format("Delete Property Fee {0:d} fails.", feeModel.PropertyFeeId), "fail", ex));
            }
        }