Пример #1
0
        public JsonResult Create(string model)
        {
            if (!AuthorizationProvider.CanEditRevenue())
            {
                return(Forbidden());
            }

            var entity = JsonConvert.DeserializeObject <ExpenseRevenueModel>(model);

            try
            {
                // parameter is passed in as a model with Json string
                var dataProvider = new ExpenseRevenueProvider(_dbContext);
                dataProvider.Create(entity);
                dataProvider.Commit();

                if (entity.ExpenseId == 0)
                {
                    entity.ExpenseId = dataProvider.GetKey(entity);
                }

                entity.ParentId = entity.ExpenseId;
                dataProvider.Update(entity.ExpenseId, entity);
                dataProvider.Commit();

                return(Json(entity, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var    innerErrorMessage = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                string message           = string.Format("Saving Expense {0:d} fails. {1} - {2}", entity.ExpenseId, ex.Message, innerErrorMessage);
                return(InternalError(message, string.Empty));
            }
        }
Пример #2
0
        public JsonResult Delete(string model)
        {
            if (!AuthorizationProvider.CanEditRevenue())
            {
                return(Forbidden());
            }

            // parameter is passed in as a model with Json string
            var entity = JsonConvert.DeserializeObject <ExpenseRevenueModel>(model);

            try
            {
                if (entity.Children.Count == 0)
                {
                    var dataProvider = new ExpenseRevenueProvider(_dbContext);
                    dataProvider.Delete(entity.ExpenseId);
                    dataProvider.Commit();
                }
                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(InternalError(string.Format("Delete Expense {0:d} fails.", entity.ExpenseId), "fail", ex));
            }
        }