public void Update(AdvContentInfoModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            using (var db = new BaseDatabaseContext())
            {
                var oldEntity = db.AdvContentInfos.FirstOrDefault(q => q.Id == model.Id);

                if (oldEntity == null)
                {
                    throw new Exception("oldEntity is null");
                }
                oldEntity = model.ToEntity(oldEntity);
                db.SaveChanges();
            }
        }
Exemple #2
0
        public ActionResult EditAdvContent(AdvContentInfoModel paraModel, FormCollection form)
        {
            var model = new BaseReturnModel()
            {
                IsSuccess = false, ReturnMsg = "操作失败"
            };

            try
            {
                var entityModel = _advContentInfoService.GetById(paraModel.Id);

                entityModel.AdvertisingSpaceInfoSign = paraModel.AdvertisingSpaceInfoSign;
                entityModel.Title              = paraModel.Title;
                entityModel.Order              = paraModel.Order;
                entityModel.Intro              = paraModel.Intro;
                entityModel.TargetType         = paraModel.TargetType;
                entityModel.ContentJsonKeyword = paraModel.ContentJsonKeyword;
                entityModel.Price              = paraModel.Price;
                entityModel.BeginDatetime      = paraModel.BeginDatetime;
                entityModel.EndDateTime        = paraModel.EndDateTime;
                entityModel.Type = paraModel.Type;

                switch (paraModel.Type)
                {
                case AdvContentInfoType.Word:
                    var wordModel = new AdvContentWordModel()
                    {
                        WordTitle = form["WordTitle"],
                        WordSize  = form["WordSize"],
                        WordColor = form["WordColor"],
                        WordLink  = form["WordLink"]
                    };
                    entityModel.ContentJson = JsonConvert.SerializeObject(wordModel);
                    break;

                case AdvContentInfoType.Pic:
                    var picModel = new AdvContentPicModel()
                    {
                        PicUrl      = form["PicUrl"],
                        PicImageAlt = form["PicImageAlt"],
                        PicLink     = form["PicLink"]
                    };
                    entityModel.ContentJson = JsonConvert.SerializeObject(picModel);
                    break;

                default:
                    break;
                }

                _advContentInfoService.Update(entityModel);

                model.IsSuccess = true;
                model.ReturnMsg = "编辑完成";
            }
            catch (Exception ex)
            {
                model.IsSuccess = false;
                model.ReturnMsg = ex.Message;
            }

            return(Json(model));
        }
Exemple #3
0
 public static AdvContentInfo ToEntity(this AdvContentInfoModel model, AdvContentInfo destination)
 {
     return(model.MapTo(destination));
 }
 public EditAdvContentModel()
 {
     AdvContentInfoModel = new AdvContentInfoModel();
     AdvContentPicModel  = new AdvContentPicModel();
     AdvContentWordModel = new AdvContentWordModel();
 }
Exemple #5
0
 public static AdvContentInfo ToEntity(this AdvContentInfoModel model)
 {
     return(model.MapTo <AdvContentInfoModel, AdvContentInfo>());
 }