コード例 #1
0
        public JsonResult Add(ChronicleIM vm)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }

            var chronicle = _mapper.Map <ChronicleIM, Chronicle>(vm);
            var result    = _chronicleService.Create(chronicle);

            if (result != null)
            {
                var pageMeta = new PageMeta()
                {
                    ObjectId    = result.ToString(),
                    Title       = string.IsNullOrEmpty(vm.SEOTitle) ? vm.Title : vm.SEOTitle,
                    Keyword     = string.IsNullOrEmpty(vm.Keywords) ? vm.Title : vm.Keywords.Replace(',', ','),
                    Description = vm.SEODescription,
                    ModelType   = ModelType.CHRONICLE
                };
                _pageMetaServices.Create(pageMeta);
            }

            int count;
            int pageSize = SettingsManager.Chronicle.PageSize;
            var list     = _chronicleService.GetPagedElements(0, pageSize, string.Empty, out count);
            List <ChronicleVM> chronicleList = _mapper.Map <List <Chronicle>, List <ChronicleVM> >(list);

            AR.Data = RenderPartialViewToString("_ChronicleList", chronicleList);

            AR.SetSuccess(String.Format(Messages.AlertCreateSuccess, EntityNames.Chronicle));
            return(Json(AR, JsonRequestBehavior.DenyGet));
        }
コード例 #2
0
        public ActionResult Add()
        {
            var vCategory = new ChronicleIM
            {
                Active = true
            };

            ViewBag.Years  = new SelectList(DateTimeHelper.GetYearList(2010));
            ViewBag.Months = new SelectList(DateTimeHelper.GetMonthList());
            ViewBag.Days   = new SelectList(DateTimeHelper.GetDayList());

            return(PartialView("_Add", vCategory));
        }
コード例 #3
0
        public JsonResult Edit(ChronicleIM vm)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR, JsonRequestBehavior.DenyGet));
            }

            var old       = _chronicleService.GetById(vm.Id);
            var chronicle = _mapper.Map(vm, old);

            //chronicle.Active = vm.Active;
            //chronicle.Year = vm.Year;
            //chronicle.Title = vm.Title;
            //chronicle.Month = vm.Month;
            //chronicle.Day = vm.Day;
            //chronicle = _mapper.Map<ChronicleIM, Chronicle>(vm);
            _chronicleService.Update(chronicle);

            var pageMeta = _pageMetaServices.GetPageMeta(ModelType.CHRONICLE, chronicle.Id.ToString());

            pageMeta = pageMeta ?? new PageMeta();

            pageMeta.ObjectId    = vm.Id.ToString();
            pageMeta.Title       = string.IsNullOrEmpty(vm.SEOTitle) ? vm.Title : vm.SEOTitle;
            pageMeta.Keyword     = string.IsNullOrEmpty(vm.Keywords) ? vm.Title : vm.Keywords.Replace(',', ',');
            pageMeta.Description = vm.SEODescription;
            pageMeta.ModelType   = ModelType.CHRONICLE;

            if (pageMeta.Id > 0)
            {
                _pageMetaServices.Update(pageMeta);
            }
            else
            {
                _pageMetaServices.Create(pageMeta);
            }

            var chronicleVM = _mapper.Map <ChronicleVM>(chronicle);

            AR.Id   = chronicle.Id;
            AR.Data = RenderPartialViewToString("_ChronicleItem", chronicleVM);

            AR.SetSuccess(String.Format(Messages.AlertUpdateSuccess, EntityNames.Chronicle));
            return(Json(AR, JsonRequestBehavior.DenyGet));
        }