public void Insert(AdvContentInfo entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     using (var db = new BaseDatabaseContext())
     {
         db.AdvContentInfos.Add(entity);
         db.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public static AdvContentInfoModel ToModel(this AdvContentInfo entity)
 {
     return(entity.MapTo <AdvContentInfo, AdvContentInfoModel>());
 }
Exemplo n.º 3
0
        public ActionResult AddAdvContent(AdvContentInfoModel paraModel, FormCollection form)
        {
            var model = new BaseReturnModel()
            {
                IsSuccess = false, ReturnMsg = "操作失败"
            };

            try
            {
                var entity = new AdvContentInfo()
                {
                    AdvertisingSpaceInfoSign = paraModel.AdvertisingSpaceInfoSign,
                    Title              = paraModel.Title,
                    Order              = paraModel.Order,
                    Intro              = paraModel.Intro,
                    TargetType         = paraModel.TargetType,
                    ContentJsonKeyword = paraModel.ContentJsonKeyword,
                    Price              = paraModel.Price,
                    BeginDatetime      = paraModel.BeginDatetime,
                    EndDateTime        = paraModel.EndDateTime,
                    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"]
                    };
                    entity.ContentJson = JsonConvert.SerializeObject(wordModel);
                    break;

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

                default:
                    break;
                }

                _advContentInfoService.Insert(entity);

                model.IsSuccess = true;
                model.ReturnMsg = "添加完成";
            }
            catch (Exception ex)
            {
                model.IsSuccess = false;
                model.ReturnMsg = ex.Message;
            }
            return(Json(model));
        }
Exemplo n.º 4
0
 public static AdvContentInfo ToEntity(this AdvContentInfoModel model, AdvContentInfo destination)
 {
     return(model.MapTo(destination));
 }