public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Email,Message")] GuestBook guestBook) { if (id != guestBook.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(guestBook); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GuestBookExists(guestBook.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(guestBook)); }
public async Task <IActionResult> PutGuestBook([FromRoute] int id, [FromBody] GuestBook guestBook) { try { if (id != guestBook.gID) { return(BadRequest()); } bool flag = await guestBookService.Update(guestBook); return(Ok(new { success = flag })); } catch (Exception ex) { loggerHelper.Error("GuestBooksController.PutGuestBook", "异常位置:GuestBooksController.PutGuestBook" + "异常消息:" + ex.Message); return(Ok(new { success = false, message = ex.Message })); } }
public async Task <ActionResult> GetGuestBookDetails(string ID) { if (!string.IsNullOrEmpty(ID)) { int GuestBookID = Convert.ToInt32(ID); GuestBook findGB = await GuestBookRepository.FindAsync(g => g.GuestBookID == GuestBookID); if (findGB != null) { return(Json(new { Success = true, GuestBookID = findGB.GuestBookID, GuestContent = findGB.GuestContent, GuestDate = findGB.GuestDate.ToString("yyyy-MM-dd"), GuestMobile = findGB.GuestMobile, GuestName = findGB.GuestName }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = false }, JsonRequestBehavior.AllowGet)); }
public GuestBook CreateNewGuestBook(GuestBook guestBook) { _context.GuestBooks.Add(guestBook); _context.SaveChanges(); return(guestBook); }
public IActionResult Index() { IList <GuestBook> items = new List <GuestBook>(); // koneksi database MySqlConnection conn = new MySqlConnection { ConnectionString = Startup.ConnectionString }; conn.Open(); // menyiapkan query MySqlCommand cmd = new MySqlCommand("SELECT * FROM guestbooks;", conn); // membaca data MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { // menyimpan record ke object model GuestBook item = new GuestBook(); item.Email = Convert.ToString(dataReader["guest_email"]); item.Name = Convert.ToString(dataReader["guest_name"]); item.Message = Convert.ToString(dataReader["message"]); // menyimpan object model ke collection items.Add(item); } dataReader.Close(); return(View(items)); }
public IActionResult Index(GuestBook data) { ViewBag.GuestBookMessage = "Hello " + data.Name + "(" + data.Email + ") menulis " + data.Message; return(View()); }
private static void SearchGuestByID() { try { int searchGuestID; Console.WriteLine("Enter GuestID to Search:"); searchGuestID = Convert.ToInt32(Console.ReadLine()); GuestBook searchGuest = GuestBL.SearchGuestBL(searchGuestID); if (searchGuest != null) { Console.WriteLine("******************************************************************************"); Console.WriteLine("GuestID\t\tName\t\tPhoneNumber"); Console.WriteLine("******************************************************************************"); Console.WriteLine("{0}\t\t{1}\t\t{2}", searchGuest.GuestID, searchGuest.GuestName, searchGuest.GuestContactNumber); Console.WriteLine("******************************************************************************"); } else { Console.WriteLine("No Guest Details Available"); } } catch (GuestException ex) { Console.WriteLine(ex.Message); } }
public async Task <string> SendConfirmationEmail(GuestBook Guest) { try { var body = string.Format(@"<h3>Thank you for contacting Elizabeth and Brian!</h3> <p>{0}, <br/>We appreciate you reaching out to us. One of us will be getting back to you shortly. <br/><br/>Please see the message you sent to us through our website,<a href="www.harneyhall.com">HarneyHall.com</a>: <br/> Name: {1} <br/>Email: {2} <br/>Phone: {3} <br/>Message: {4}</p><br/><br/>Call Brian at (630)849-6948 or Elizabeth at (708)310-5765", Guest.Name, Guest.Name, Guest.Email, Guest.Phone, Guest.Message); var recipients = new List <EmailAddress>() { new EmailAddress(_config["MailService:Receiver1Name"], _config["MailService:Receiver1"]), new EmailAddress(_config["MailService:Receiver2Name"], _config["MailService:Receiver2"]), new EmailAddress(Guest.Email) }; var from = new EmailAddress("HarneyHall RSVP", _config["MailService:RsvpFrom"]); var subject = "Secret Wedding Message Sent!"; var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, recipients, subject, null, body); var client = new SendGridClient(_config["MailService:ApiKey"]); var response = await client.SendEmailAsync(msg); return("successfully sent email"); } catch (Exception e) { return(e.Message); } }
private static void UpdateGuest() { try { int updateGuestID; Console.WriteLine("Enter GuestID to Update Details:"); updateGuestID = Convert.ToInt32(Console.ReadLine()); GuestBook updatedGuest = GuestBL.SearchGuestBL(updateGuestID); if (updatedGuest != null) { Console.WriteLine("Update Guest Name :"); updatedGuest.GuestName = Console.ReadLine(); Console.WriteLine("Update PhoneNumber :"); updatedGuest.GuestContactNumber = Console.ReadLine(); bool guestUpdated = GuestBL.UpdateGuestBL(updatedGuest); if (guestUpdated) { Console.WriteLine("Guest Details Updated"); } else { Console.WriteLine("Guest Details not Updated "); } } else { Console.WriteLine("No Guest Details Available"); } } catch (GuestException ex) { Console.WriteLine(ex.Message); } }
private static void DeleteGuest() { try { int deleteGuestID; Console.WriteLine("Enter GuestID to Delete:"); deleteGuestID = Convert.ToInt32(Console.ReadLine()); GuestBook deleteGuest = GuestBL.SearchGuestBL(deleteGuestID); if (deleteGuest != null) { bool guestdeleted = GuestBL.DeleteGuestBL(deleteGuestID); if (guestdeleted) { Console.WriteLine("Guest Deleted"); } else { Console.WriteLine("Guest not Deleted "); } } else { Console.WriteLine("No Guest Details Available"); } } catch (GuestException ex) { Console.WriteLine(ex.Message); } }
public async Task <IActionResult> PostGuestBook([FromBody] GuestBook guestBook) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Guestbooks.Add(guestBook); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (GuestBookExists(guestBook.GuestBookId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetGuestBook", new { id = guestBook.GuestBookId }, guestBook)); }
public bool AddComment(GuestBook newItem) { SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_insertComments"; cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = newItem.Name; cmd.Parameters.Add("@comment", SqlDbType.VarChar).Value = newItem.Comment; try { con.Open(); cmd.ExecuteNonQuery(); } catch (System.Exception ex) { throw ex; } finally { cmd.Dispose(); cmd = null; con.Close(); } return(true); }
public async Task <IActionResult> PutGuestBook([FromRoute] int id, [FromBody] GuestBook guestBook) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != guestBook.GuestBookId) { return(BadRequest()); } _context.Entry(guestBook).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GuestBookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static void PopulateTestData(AppDbContext dbContext) { var toDos = dbContext.ToDoItems; foreach (var item in toDos) { dbContext.Remove(item); } dbContext.SaveChanges(); dbContext.ToDoItems.Add(new ToDoItem() { Title = "Test Item 1", Description = "Test Description One" }); dbContext.ToDoItems.Add(new ToDoItem() { Title = "Test Item 2", Description = "Test Description Two" }); var guestbook = new GuestBook(); dbContext.GuestBooks.Add(guestbook); guestbook.Entries.Add(new GuestBookEntry() { EmailAddress = "*****@*****.**", Message = "Test message" }); dbContext.SaveChanges(); }
private static void AddGuest() { try { GuestBook newGuest = new GuestBook(); //Console.WriteLine("Enter GuestID :"); //newGuest.GuestID = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Guest Name :"); newGuest.GuestName = Console.ReadLine(); Console.WriteLine("Enter PhoneNumber :"); newGuest.GuestContactNumber = Console.ReadLine(); bool guestAdded = GuestBL.AddGuestBL(newGuest); if (guestAdded) { Console.WriteLine("Guest Added"); } else { Console.WriteLine("Guest not Added"); } } catch (GuestException ex) { Console.WriteLine(ex.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }
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 bool UpdateGuestDAL(GuestBook guest) { bool guestupdated = false; try { GuestBook oldGuest = null; oldGuest = context.Guests.Where(g => g.GuestID == guest.GuestID).Select(g => g).FirstOrDefault(); if (oldGuest != null) { oldGuest.GuestName = guest.GuestName; oldGuest.GuestContactNumber = guest.GuestContactNumber; int status = context.SaveChanges(); if (status > 0) { guestupdated = true; } } } catch (Exception ex) { throw new GuestException(ex.Message); } return(guestupdated); }
public IActionResult Index() { GuestBook guestBook = new GuestBook(); guestBook.setUpMe(); return(View(guestBook)); }
public void DeleteGuestBook(GuestBookViewModel GuestBook) { GuestBook entity = _guestBookRepository.GetById(GuestBook.Id); entity.Status = (int)DbConstant.DefaultDataStatus.Deleted; _guestBookRepository.Update(entity); _unitOfWork.SaveChanges(); }
public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); HotelGuestbook = new GuestBook("HotelGuestbook"); Application.Run(new Reservations.ReservationsListForm()); }
public IActionResult GuestBookCreate(GuestBook item) { if (ModelState.IsValid) { db.Add(item); db.SaveChanges(); return(RedirectToAction("GuestBookList")); } return(View()); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,Message")] GuestBook guestBook) { if (ModelState.IsValid) { _context.Add(guestBook); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(guestBook)); }
public IActionResult Submit(GuestBook guestBook, string firstName, string lastName, string entry) { // using the addEntry method adds a entry to the database guestBook.addEntry(firstName, lastName, entry); // sets the value of the checkbox to true so the form will stay open guestBook.check = true; // refresh the table to get the new entry guestBook.setUpMe(); return(View("Index", guestBook)); }
public ActionResult Write([Bind(Include = "Id,姓名,Email,内容")] GuestBook guestBook) { if (ModelState.IsValid) { db.GuestBooks.Add(guestBook); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(guestBook)); }
public ActionResult Create(GuestBook message) { //Create the new comment if (ModelState.IsValid) { message.CreatedDate = DateTime.Now; context.Add(message); context.SaveChanges(); return(RedirectToAction("")); } return(View()); }
public async Task ContactAsync([FromBody] Contact guest) { if (ModelState.IsValid) { GuestBook Guest = new GuestBook(guest.Name, guest.Email, guest.Phone, guest.Message); EmailingService emailingService = new EmailingService(_config); await emailingService.SendConfirmationEmail(Guest); } }
public IActionResult Create(GuestBook item) { if (ModelState.IsValid) { GuestBookDataContext db = new GuestBookDataContext(); db.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
protected void btnSubmit_Click(object Sender, EventArgs e) { String nick = this.txtNick.Text; String title = this.txtTitle.Text; String note = this.txtNote.Text; if (!GuestBook.Add(nick, title, note)) { this.lblMsg.Text = "留言失败"; } BindData(); }
public ActionResult Create(GuestEntry entry) { if (entry.Name == "Fido") { throw new InvalidOperationException("No dogs allowed"); } var book = new GuestBook(); book.Add(entry); return(RedirectToAction("List")); }
public ActionResult Index(GuestBook model, int? page) { var children = _pageRepository.GetChildren(model).OfType<Comment>(); //foreach(var child in children) { // child.Metadata.Slug = child.Id; // child.Metadata.Url=child.Id; // _pageRepository.Delete(child); //} //_pageRepository.SaveChanges(); var viewModel = new GuestBookViewModel(model, _structureInfo, children) { CurrentPage = page.GetValueOrDefault(0) }; if (!HttpContext.Request.IsAjaxRequest()) return View(viewModel); return PartialView("CommentList", viewModel); }
public GuestBook SearchGuestDAL(int guestID) { GuestBook searchedGuest = null; try { searchedGuest = context.Guests.Where(g => g.GuestID == guestID).Select(g => g).FirstOrDefault(); } catch (Exception ex) { throw new GuestException(ex.Message); } return(searchedGuest); }
public GuestBookController(IPageRepository pageRepository, IStructureInfo structureInfo,IPageModel currentPage) { _currentPage = currentPage as GuestBook; _pageRepository = pageRepository; _structureInfo = structureInfo; }