Example #1
0
        public static bool SendHKNews(HKNewsPaper paper)
        {
            dynamic email = new Email("~/MailTemplates/HKNews.cshtml");
            email.Model = paper;
            email.Send();

            return true;
        }
Example #2
0
 public void AddHKNewsPaper(HKNewsPaper model)
 {
     model.Created = DateTime.Now;
     db.HKNewsPaper.Add(model);
     Save();
 }
Example #3
0
 public HKNewsPaper PaperFromViewModel()
 {
     HKNewsPaper retVal = new HKNewsPaper
     {
         MailId = this.Id,
         Sender = this.UserId,
         RPublisher = this.RPublisher,
         REditor = this.REditor,
         Title = this.Title,
         IsDraft = this.IsDraft,
         Sent = this.Sent,
         Created = this.Created
     };
     foreach (var item in this.NewsItems)
     {
         retVal.HKNewsItem.Add(new HKNewsItem
         {
             ItemId = item.Id,
             MailId = this.Id,
             Title = item.Title,
             Link = item.Link,
             Body = item.Body
         });
     }
     return retVal;
 }
Example #4
0
        public void UpdateHKNewsPaper(HKNewsPaper model)
        {
            db.HKNewsPaper.AddOrUpdate(model);

            var itemids = model.HKNewsItem.Select(x => x.ItemId);
            var delete = db.HKNewsItem.Where(s => s.MailId == model.MailId).AsEnumerable().Except<HKNewsItem>(db.HKNewsItem.Where(s => itemids.Contains(s.ItemId)));
            db.HKNewsItem.RemoveRange(delete);

            foreach (var item in model.HKNewsItem)
            {
                db.HKNewsItem.AddOrUpdate(item);
            }

            Save();
        }
Example #5
0
 public static HKNewsPaperViewModel ViewModelFromPaper(HKNewsPaper p)
 {
     HKNewsPaperViewModel retVal = new HKNewsPaperViewModel
     {
         Id = p.MailId,
         UserId = p.Sender,
         UserName = AccountHelper.FullNameById(p.Sender),
         RPublisher = p.RPublisher,
         REditor = p.REditor,
         Title = p.Title,
         IsNew = false,
         Sent = p.Sent,
         Created = p.Created
     };
     foreach (var item in p.HKNewsItem)
     {
         retVal.NewsItems.Add(new HKNewsItemViewModel
         {
             Id = item.ItemId,
             Title = item.Title,
             Link = item.Link,
             Body = item.Body
         });
     }
     if (retVal.UserId == null && retVal.UserName == null && AccountHelper.IsAuthenticated())
     {
         var cu = AccountHelper.CurrentUser();
         retVal.UserName = cu.FullName;
         retVal.UserId = cu.UserId;
     }
     return retVal;
 }