Пример #1
0
        public JsonResult GetGoodgovernance(long id)
        {
            try
            {
                GoodGovernance goodGovernance = GoodGovernance.Get(SessionContext, id);

                if (goodGovernance == null)
                {
                    SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Get, MessageException.Null("The static method Get return null, ID : " + id));
                    return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                }

                GoodGovernanceViewModel goodGovernanceViewModel = new GoodGovernanceViewModel
                {
                    ID   = goodGovernance.ID,
                    Name = goodGovernance.Name,
                };

                return(Json(new { Success = true, goodGovernanceViewModel }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Get, MessageException.Fail(ex.Message));
                return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        public void Get_Test()
        {
            //Arrage
            var good = GoodGovernance.Get(context, 1L);

            //Act
            long id = 1L;

            //Assert
            Assert.AreEqual(good.ID, id);
        }
Пример #3
0
        public void GetAll_Test()
        {
            //Arrage
            var goods = GoodGovernance.GetAll(context);

            //Act
            int size = 0;

            //Assert
            Assert.IsTrue(goods.Count >= size);
        }
Пример #4
0
        public void Constructor_test()
        {
            //Arrage
            var good = new GoodGovernance();

            //Act
            TimeInterval effective = new TimeInterval(DateTime.Now, new DateTime(2300, 12, 31));

            //Assert
            Assert.AreEqual(good.EffectivePeriod.From.Date, effective.From.Date);
            Assert.AreEqual(good.EffectivePeriod.To.Date, effective.To.Date);
        }
Пример #5
0
        public void Event_Test_new()
        {
            //Arrage
            var good = new GoodGovernance();

            //Act
            string eventStr = string.Format("{0} | {1}",
                                            "<a href='#' onclick='editGoodGovernance(" + 0 + ")' class='event link'>แก้ไข</a>",
                                            "<a href='#' onclick='deleteGoodGovernance(" + 0 + ")' class='event link'>ลบ</a>");

            //Assert
            Assert.AreEqual(good.Event, eventStr);
        }
Пример #6
0
        public void GetEffective_Test()
        {
            //Arrage
            var goodEffectives = GoodGovernance.GetEffectives(context);

            //Act
            DateTime yesterday = DateTime.Now.AddDays(-1);

            //Assert
            foreach (var item in goodEffectives)
            {
                Assert.IsTrue(item.EffectivePeriod.To >= yesterday);
                Assert.IsTrue(item.IsEffective);
            }
        }
Пример #7
0
        public JsonResult GetGoodGovernances()
        {
            IList <GoodGovernance> goodGovernances = null;

            try
            {
                goodGovernances = GoodGovernance.GetAll(SessionContext);
            }
            catch (Exception ex)
            {
                SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Gets, MessageException.Fail(ex.Message));
            }

            return(Json(goodGovernances, JsonRequestBehavior.AllowGet));
        }
Пример #8
0
        public JsonResult Update(long id, string name)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Null("The name is emptry."));
                    return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                }

                GoodGovernance goodGovernance = GoodGovernance.Get(SessionContext, id);

                if (goodGovernance == null)
                {
                    SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Null("The static method Get return null, ID : " + id));
                    return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                }

                using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
                {
                    try
                    {
                        goodGovernance.Name            = name;
                        goodGovernance.UpdateAction    = new UserAction(SessionContext.User);
                        goodGovernance.EffectivePeriod = TimeInterval.EffectiveNow;

                        tx.Commit();

                        SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Success(id.ToString()));
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();

                        SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Fail(ex.Message));
                        return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Fail(ex.Message));
                return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { Success = true, Message = "แก้ไขหลักธรรมาภิบาล เรียบร้อย" }, JsonRequestBehavior.AllowGet));
        }
Пример #9
0
        public JsonResult Save(string name)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Save, MessageException.Null("The name is emptry."));
                    return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                }

                using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
                {
                    try
                    {
                        GoodGovernance goodGovernance = new GoodGovernance {
                            Name = name
                        };

                        goodGovernance.CreateAction    = new UserAction(SessionContext.User);
                        goodGovernance.EffectivePeriod = TimeInterval.EffectiveNow;
                        goodGovernance.Persist(SessionContext);

                        tx.Commit();

                        SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Save, MessageException.Success());
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();

                        SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Save, MessageException.Fail(ex.Message));
                        return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Save, MessageException.Fail(ex.Message));
                return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { Success = true, Message = "เพิ่มหลักธรรมาภิบาล เรียบร้อย" }, JsonRequestBehavior.AllowGet));
        }
Пример #10
0
        public JsonResult GetGoodGovernances()
        {
            IList <GoodGovernance>          goodGovernances          = null;
            IList <GoodGovernanceViewModel> goodGovernanceViewModels = null;

            try
            {
                goodGovernances          = GoodGovernance.GetEffectives(SessionContext);
                goodGovernanceViewModels = goodGovernances.Select(x => new GoodGovernanceViewModel
                {
                    ID   = x.ID,
                    Name = x.Name,
                }).ToList();
            }
            catch (Exception ex)
            {
                SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Gets, MessageException.Fail(ex.Message));
            }
            return(Json(goodGovernanceViewModels, JsonRequestBehavior.AllowGet));
        }
Пример #11
0
        public JsonResult Delete(long id)
        {
            try
            {
                GoodGovernance goodGovernance = GoodGovernance.Get(SessionContext, id);

                if (goodGovernance == null)
                {
                    SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Delete, MessageException.Null("The static method Get return null, ID : " + id));
                    return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                }

                using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
                {
                    try
                    {
                        goodGovernance.EffectivePeriod = new TimeInterval(TimeInterval.MaxDate, TimeInterval.MinDate);
                        goodGovernance.UpdateAction    = new UserAction(SessionContext.User);
                        //goodGovernance.Delete(SessionContext);

                        tx.Commit();

                        SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Delete, MessageException.Success(id.ToString()));
                    }
                    catch (Exception ex)
                    {
                        tx.Rollback();

                        SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Delete, MessageException.Fail(ex.Message));
                        return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Delete, MessageException.Fail(ex.Message));
                return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { Success = true, Message = "ลบหลักธรรมาภิบาล เรียบร้อย" }, JsonRequestBehavior.AllowGet));
        }