Beispiel #1
0
        protected FaqCategoryViewModel ToViewModel(FaqCategory category)
        {
            FaqCategoryViewModel vm = Mapper.Map <FaqCategoryViewModel>(category);

            vm.Items = category.FaqItems.Select(ToViewModel);
            return(vm);
        }
        public void UpsertPostCategoryEmptyModel()
        {
            ////Arrange
            var model   = new FaqCategoryViewModel();
            var request = new DataSourceRequest();
            ////Act
            var result = faqController.UpsertCategory(request, model);

            SimulateValidation(model, faqController);
            ////Assert
            faqController.ModelState.IsValid.Should().Be(false);
        }
        public JsonResult Save(FaqCategoryViewModel model)
        {
            var currentUser = GetAuthenticatedUser();

            try
            {
                if (string.IsNullOrEmpty(model.title))
                {
                    return(Error("وارد کردن نام دسته بندی اجباری است."));
                }

                if (model.id != null && model.id > 0)
                {
                    var entity = _context.FaqCategory.Single(x => x.StatusId != FaqCategoryStatus.Deleted.Id && x.Id == model.id);
                    entity.Title        = model.title.ToStandardPersian();
                    entity.Order        = model.order;
                    entity.StatusId     = model.statusId;
                    entity.ModifyUserId = currentUser.id;
                    entity.ModifyDate   = GetDatetime();
                    entity.ModifyIp     = GetCurrentIp();

                    _context.SaveChanges();

                    return(Success("اطلاعات دسته بندی با موفقیت ویرایش شد."));
                }
                else
                {
                    var entity = new FaqCategory()
                    {
                        Title        = model.title.ToStandardPersian(),
                        Order        = model.order,
                        StatusId     = model.statusId,
                        CreateUserId = currentUser.id,
                        ModifyUserId = currentUser.id,
                        CreateDate   = GetDatetime(),
                        ModifyDate   = GetDatetime(),
                        CreateIp     = GetCurrentIp(),
                        ModifyIp     = GetCurrentIp()
                    };

                    _context.FaqCategory.Add(entity);
                    _context.SaveChanges();

                    return(Success("دسته بندی با موفقیت ایجاد شد."));
                }
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }
        public ActionResult UpsertCategory(Guid?id)
        {
            var model = new FaqCategoryViewModel();

            if (id.HasValue)
            {
                using (ContextManager.NewConnection())
                {
                    model = Mapper.Map <FaqCategoryViewModel>(faqService.GetFaqCategory(id.Value, true));
                }
            }

            return(PartialView(model));
        }
        public ActionResult UpsertCategory([DataSourceRequest] DataSourceRequest request, FaqCategoryViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                using (var transaction = ContextManager.NewTransaction())
                {
                    var entity = Mapper.Map <FaqCategory>(model);
                    model.Id = faqService.UpsertFaqCategory(entity);
                    transaction.Commit();
                }
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }