예제 #1
0
        public TNews GetByType(EnumNewsType enumNewsType)
        {
            ICriteria criteria = Session.CreateCriteria(typeof(TNews));

            //get list results
            criteria.Add(Restrictions.Eq("NewsType", enumNewsType.ToString()));
            criteria.SetMaxResults(1);

            return(criteria.UniqueResult <TNews>());
        }
예제 #2
0
        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));
        }