Пример #1
0
        public ActionResult Create()
        {
            var model = new CategoryFormModel();

            try
            {
                var category = CategoryService.CategoryNew();

                this.Map(category, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return this.View(model);
        }
Пример #2
0
        public ActionResult Create(CategoryFormModel model)
        {
            var category = CategoryService.CategoryNew();

            Csla.Data.DataMapper.Map(model, category, true);

            category = CategoryService.CategorySave(category);

            if (category.IsValid)
            {
                return new JsonResult { Data = this.Url.Action("Edit", new { id = category.CategoryId, message = Resources.SaveSuccessfulMessage }) };
            }

            this.Map(category, model, false);

            return this.View(model);
        }
Пример #3
0
        public ActionResult Edit(int id, string message)
        {
            var model = new CategoryFormModel();

            try
            {
                var category = CategoryService.CategoryFetch(id);

                model.Message = message;

                this.Map(category, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return this.View(model);
        }
Пример #4
0
        public ActionResult Edit(int id, CategoryFormModel model)
        {
            var category = CategoryService.CategoryFetch(id);

            Csla.Data.DataMapper.Map(model, category, true);

            category = CategoryService.CategorySave(category);

            if (category.IsValid)
            {
                model.Message = Resources.SaveSuccessfulMessage;
            }

            this.Map(category, model, true);

            return this.View(model);
        }
Пример #5
0
        public CategoryFormModel Map(Category category, CategoryFormModel model, bool ignoreBrokenRules)
        {
            Csla.Data.DataMapper.Map(category, model, true);

            model.Tab = "Home";
            model.IsNew = category.IsNew;
            model.IsValid = category.IsValid;

            if (!ignoreBrokenRules)
            {
                foreach (var brokenRule in category.BrokenRulesCollection)
                {
                    this.ModelState.AddModelError(string.Empty, brokenRule.Description);
                }
            }

            return model;
        }