コード例 #1
0
ファイル: NpcMmsesController.cs プロジェクト: chenchunwei/NPC
 public ActionResult EditNpcMmsPost(EditNpcMmsModel model)
 {
     model.FrameSerializers = JsonConvert.DeserializeObject<IList<FrameSerializer>>(model.FormData.Frames);
     var npcMms = model.Id.HasValue ? _npcMmsAction.UpdateNpcMms(model) : _npcMmsAction.NewNpcMms(model);
     if (model.IsSend)
         return RedirectToAction("EditNpcMmsSend", "NpcMmsSends", new { npcMmsId = npcMms.Id });
     return RedirectToMessage("手机报彩信保存成功");
 }
コード例 #2
0
ファイル: NpcMmsAction.cs プロジェクト: chenchunwei/NPC
 public EditNpcMmsModel InitializeEditNpcMmsModel(Guid? id)
 {
     var model = new EditNpcMmsModel();
     if (id.HasValue)
     {
         var npcMms = _npcMmsRepository.Find(id.Value);
         npcMms.NpcMmsContents.ToList().ForEach(npcContent =>
             model.FrameSerializers.Add(new FrameSerializer()
             {
                 Image = npcContent.UrlOfPic,
                 OrderSort = npcContent.OrderSort,
                 Text = npcContent.Content,
                 TimeDuring = npcContent.DueTime,
                 Voice = npcContent.UrlOfVoice,
                 Id = npcContent.Id
             }));
         model.FormData.LayoutType = npcMms.LayoutType;
         model.FormData.Title = npcMms.Title;
     }
     return model;
 }
コード例 #3
0
ファイル: NpcMmsAction.cs プロジェクト: chenchunwei/NPC
 public NpcMms NewNpcMms(EditNpcMmsModel model)
 {
     var trans = TransactionManager.BeginTransaction();
     try
     {
         var npcMms = new NpcMms();
         npcMms.Title = model.FormData.Title;
         npcMms.Unit = NpcContext.CurrentUser.Unit;
         npcMms.RecordDescription.CreateBy(NpcContext.CurrentUser);
         model.FrameSerializers.ToList().ForEach(frame =>
         {
             if (string.IsNullOrEmpty(frame.Image) &&
                 string.IsNullOrEmpty(frame.Image) &&
                 string.IsNullOrEmpty(frame.Voice))
             {
                 return;
             }
             var content = new NpcMmsContent()
             {
                 Content = frame.Text,
                 DueTime = frame.TimeDuring,
                 LayoutType = model.FormData.LayoutType,
                 OrderSort = frame.OrderSort,
                 UrlOfPic = frame.Image,
                 UrlOfVoice = frame.Voice
             };
             npcMms.LayoutType = model.FormData.LayoutType;
             content.ByteSize = content.CalculateSize(AppConfig.AttachmentsPath);
             npcMms.NpcMmsContents.Add(content);
         });
         _npcMmsRepository.Save(npcMms);
         trans.Commit();
         return npcMms;
     }
     catch (Exception)
     {
         trans.Rollback();
         throw;
     }
 }
コード例 #4
0
ファイル: NpcMmsAction.cs プロジェクト: chenchunwei/NPC
        public NpcMms UpdateNpcMms(EditNpcMmsModel model)
        {
            if (model.Id == null)
                throw new ArgumentException("id不能为null");
            var trans = TransactionManager.BeginTransaction();

            try
            {
                var npcMms = _npcMmsRepository.Find(model.Id.Value);
                npcMms.Title = model.FormData.Title;
                npcMms.RecordDescription.UpdateBy(NpcContext.CurrentUser);
                //删除所有已为空的帧及被删除的删
                npcMms.NpcMmsContents.Where(o => model.FrameSerializers.All(oo => oo.Id != o.Id
                    || (o.Id == oo.Id && string.IsNullOrEmpty(oo.Image)
                    && string.IsNullOrEmpty(oo.Image) && string.IsNullOrEmpty(oo.Voice)))).ToList()
                      .ForEach(o => npcMms.NpcMmsContents.Remove(o));
                model.FrameSerializers.ToList().ForEach(frame =>
                {
                    if (string.IsNullOrEmpty(frame.Image) && string.IsNullOrEmpty(frame.Text) && string.IsNullOrEmpty(frame.Voice))
                    {
                        return;
                    }
                    var existContent = npcMms.NpcMmsContents.FirstOrDefault(o => o.Id == frame.Id);
                    var content = existContent ?? new NpcMmsContent();
                    content.Content = frame.Text;
                    content.DueTime = frame.TimeDuring;
                    content.LayoutType = model.FormData.LayoutType;
                    content.OrderSort = frame.OrderSort;
                    content.UrlOfPic = frame.Image;
                    content.UrlOfVoice = frame.Voice;
                    npcMms.LayoutType = model.FormData.LayoutType;
                    content.ByteSize = content.CalculateSize(AppConfig.AttachmentsPath);
                    if (existContent == null)
                        npcMms.NpcMmsContents.Add(content);
                });
                _npcMmsRepository.Save(npcMms);
                trans.Commit();
                return npcMms;
            }
            catch (Exception)
            {
                trans.Rollback();
                throw;
            }
        }