コード例 #1
0
 public ActionResult SendGuestBook(GuestBook gb)
 {
     try
     {
         if (gb != null)
         {
             gb.GuestDate = DateTime.Now.ToLocalTime();
             GuestBook addGB = GuestBookRepository.Add(gb);
             if (addGB != null)
             {
                 return(Json(new
                 {
                     Success = true
                 }));
             }
         }
         return(Json(new
         {
             Success = false
         }));
     }
     catch (Exception)
     {
         return(Json(new
         {
             Success = false
         }));
     }
 }
コード例 #2
0
        public void InsertGuestBook(GuestBookViewModel guestBook, int userId)
        {
            DateTime serverTime = DateTime.Now;

            guestBook.CreateDate   = serverTime;
            guestBook.CreateUserId = userId;
            guestBook.ModifyDate   = serverTime;
            guestBook.ModifyUserId = userId;
            guestBook.Status       = (int)DbConstant.DefaultDataStatus.Active;


            GuestBook entity = new GuestBook();

            Map(guestBook, entity);
            _guestBookRepository.AttachNavigation <Vehicle>(entity.Vehicle);
            _guestBookRepository.Add(entity);

            _unitOfWork.SaveChanges();
        }
コード例 #3
0
        public async Task <bool> TestTranInRepository()
        {
            try
            {
                Console.WriteLine($"");
                Console.WriteLine($"Begin Transaction");
                m_UnitOfWork.BeginTran();

                var passwords = await m_PasswordLibRepository.Query();

                Console.WriteLine($"First time: the count of password is: {passwords.Count}.");

                Console.WriteLine($"Insert a data into the table PasswordLib now.");
                var insertPassword = await m_PasswordLibRepository.Add(new PasswordLib()
                {
                    IsDeleted     = false,
                    PLAccountName = "aaa",
                    PLCreateTime  = DateTime.Now
                });

                passwords = await m_PasswordLibRepository.Query(d => d.IsDeleted == false);

                Console.WriteLine($"Second time: the count of passwords is: {passwords.Count}.");

                var guestbooks = await m_Dal.Query();

                Console.WriteLine($"\nFirst time: the count of guestbooks is: {guestbooks.Count}.");

                int ex = 0;
                Console.WriteLine($"\nThere's an exception!");
                int throwEx = 1 / ex;

                Console.WriteLine($"Insert a data into the table Guestbook now.");
                var insertGuestBook = await m_Dal.Add(new GuestBook()
                {
                    UserName   = "******",
                    BlogId     = 1,
                    Createdate = DateTime.Now,
                    IsShow     = true,
                });

                guestbooks = await m_Dal.Query();

                Console.WriteLine($"Second time: the count of guestbooks is: {guestbooks.Count}.");

                m_UnitOfWork.CommitTran();
                return(true);
            }
            catch (Exception)
            {
                m_UnitOfWork.RollBackTran();
                var passwords = await m_PasswordLibRepository.Query();

                Console.WriteLine($"Third time: the count of passwords is: {passwords.Count}.");

                var guestBooks = await m_Dal.Query();

                Console.WriteLine($"Third time: the count of guestbooks is: {guestBooks.Count}.");
                return(false);
            }
        }