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 })); } }
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(); }
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); } }