Beispiel #1
0
        public static HomeViewModel Create(ITNewsRepository tNewsRepository, ITLoanRepository tLoanRepository)
        {
            var   viewModel = new HomeViewModel();
            TNews news      = tNewsRepository.GetByType(EnumNewsType.Promo);

            if (news == null)
            {
                news = new TNews();
            }
            viewModel.PromoNews = news;

            news = tNewsRepository.GetByType(EnumNewsType.Announcement);
            if (news == null)
            {
                news = new TNews();
            }
            viewModel.AnnouncementNews = news;

            DateTime currentMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);

            viewModel.CurrentLoanSummary = LoanSummary.Create(tLoanRepository, currentMonth);

            viewModel.OneMonthAgoLoanSummary = LoanSummary.Create(tLoanRepository, currentMonth.AddMonths(-1));

            viewModel.OneMonthAgoAchievement = AchievementSummary.Create(tLoanRepository, currentMonth.AddMonths(-1));

            return(viewModel);
        }
        public ActionResult SaveNews(EnumNewsType newsType, string newsDesc)
        {
            string Message = string.Empty;
            bool   Success = true;

            try
            {
                TNews news = _tNewsRepository.GetByType(newsType);
                if (news == null)
                {
                    news = new TNews();
                    news.SetAssignedIdTo(Guid.NewGuid().ToString());
                    news.NewsDesc    = newsDesc;
                    news.NewsType    = newsType.ToString();
                    news.DataStatus  = EnumDataStatus.New.ToString();
                    news.CreatedBy   = User.Identity.Name;
                    news.CreatedDate = DateTime.Now;
                    _tNewsRepository.Save(news);
                }
                else
                {
                    news.NewsDesc     = newsDesc;
                    news.DataStatus   = EnumDataStatus.Updated.ToString();
                    news.ModifiedBy   = User.Identity.Name;
                    news.ModifiedDate = DateTime.Now;
                    _tNewsRepository.Update(news);
                }

                Success = true;
                Message = "Sukses";
            }
            catch (Exception ex)
            {
                Success = false;
                Message = "Error :\n" + ex.GetBaseException().Message;
            }
            var e = new
            {
                Success,
                Message
            };

            return(Json(e, JsonRequestBehavior.AllowGet));
        }