Exemplo n.º 1
0
        public ActionResult Edit(int id = 0)
        {
            if (id == 0)
            {
                HKNewsPaperViewModel model = new HKNewsPaperViewModel
                {
                    UserId = AccountHelper.CurrentUser().UserId,
                    RPublisher = SettingsApi.GetValue("hknews", "rpublisher"),
                    REditor = SettingsApi.GetValue("hknews", "reditor"),
                    UserName = AccountHelper.CurrentUser().FullName,
                    IsNew = true
                };
                model.NewsItems.Add(new HKNewsItemViewModel
                {
                    Title = "első hír",
                    Link = "http://proba.hu",
                    Body = "szöveg törgye blablabla blabla"
                });
                model.NewsItems.Add(new HKNewsItemViewModel
                {
                    Title = "második hír",
                    Link = "http://proba2.hu/megmeg",
                    Body = "szöveg törgye blablabla blabla"
                });

                ViewBag.model = new MvcHtmlString(JsonConvert.SerializeObject(model));
            }
            else
            {
                var paper = db.GetHKNewsPaperById(id);
                ViewBag.model = new MvcHtmlString(JsonConvert.SerializeObject(HKNewsPaperViewModel.ViewModelFromPaper(paper)));
            }

            return View();
        }
Exemplo n.º 2
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;
 }