コード例 #1
0
        public virtual JsonResult Manage(AdsModel model)
        {
            model.CreationDate = model.CreationDate.ToEnglish();
            model.ExpireDate   = model.ExpireDate.ToEnglish();

            var res = new OperationStatus();

            if (ModelState.IsValid)
            {
                Ad ads;
                if (model.Id > 0)
                {
                    var dbAds = _adsBiz.GetList().SingleOrDefault(a => a.Id == model.Id);
                    ads = model.ToModel <Ad>(dbAds);
                }
                else
                {
                    ads = model.ToModel <Ad>();
                }

                if (model.SelectedCategories != null)
                {
                    ads.Categories.AddEntities(_categoryBusiness.GetList(model.SelectedCategories.ToList()).ToList());
                }
                if (model.SelectedTags != null)
                {
                    ads.Tags.AddEntities(_tagBusiness.GetList().Where(t => model.SelectedTags.Contains(t.Id)).ToList());
                }

                res = _adsBiz.CreateEdit(ads);
            }
            return(Json(res.ToJOperationResult(), JsonRequestBehavior.AllowGet));
        }