public void AddEntry(GuestbookEntry entry) { entry.DateAdded = DateTime.Now; // setta il campo mancante _db.Entries.Add(entry); // aggiunge l'oggetto all'EntriesDbSet del GuestbookContext _db.SaveChanges(); // scrive sul database la nuova entry }
public ActionResult Register(RegisterModel register) { if (ModelState.IsValid) { var dbUser = db.Users.FirstOrDefault(u => u.Name == register.Name); if (dbUser == null || !string.Equals(dbUser.Name, register.Name)) { register.Password = Models.Security.MD5Hasher.ComputeHash(register.Password); db.Users.Add(new User { Name = register.Name, Password = register.Password }); db.SaveChanges(); return(RedirectToAction("Login")); } else { ModelState.AddModelError("", "Such username exists!"); return(View(register)); } } return(View(register)); }
public ActionResult Create([Bind(Include = "Id,Name,Message,DateCreated")] GuestbookEntry guestbookEntry) { if (ModelState.IsValid) { db.Entries.Add(guestbookEntry); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(guestbookEntry)); }
public ActionResult Create([Bind(Include = "Id,Name,Content")] Guestbook guestbook) { if (ModelState.IsValid) { db.Guestbooks.Add(guestbook); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(guestbook)); }
public ActionResult Create(GuestbookEntry entry) { if (ModelState.IsValid) { entry.DateAdded = DateTime.Now; _db.Entries.Add(entry); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(entry)); }
public ActionResult Create(GuestbookEntry entry) { entry.DateAdded = DateTime.Now; db.Entries.Add(entry); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,Name,Comment")] GuestbookEntry guestbookEntry) { guestbookEntry.DatePosted = DateTime.Now; if (ModelState.IsValid) { db.GuestbookEntries.Add(guestbookEntry); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(guestbookEntry)); }
public ActionResult Create([Bind(Include = "Id,MessageBody,MessageDate,UserId")] Message message) { if (ModelState.IsValid && Session["Id"] != null) { var sessionUser = new User() { Id = Convert.ToInt32(Session["Id"]), Name = Session["Name"].ToString() }; var dbUser = db.Users.FirstOrDefault(u => u.Id == sessionUser.Id); message.MessageDate = DateTime.Now; message.User = dbUser; db.Messages.Add(message); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.Users, "Id", "Name", message.User); return(View(message)); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new GuestbookContext( serviceProvider.GetRequiredService <DbContextOptions <GuestbookContext> >())) { if (context.Entries.Any()) { return; } context.Entries.AddRange(new Entry[] { new Entry { Name = "CuckooBlue", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 1, 15, 21, 43), Comment = "Don't want to close my eyes I don't want to fall asleep Cause I'd miss you babe And I don't want to miss a thing Cause even when I dream of you The sweetest dream will never do I'd still miss you babe And I don't want to miss a thing." }, new Entry { Name = "lolita", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 1, 19, 23, 32), Comment = "I saw six men kicking and punching the mother-in-law. My neighbor said 'Are you going to help?' I said, 'No, Six should be enough.'" }, new Entry { Name = "Phantonemesis", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 2, 9, 12, 16), Comment = "I am ready to meet my Maker. Whether my Maker is prepared for the great ordeal of meeting me is another matter." }, new Entry { Name = "Gobbeldy Gator", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 2, 11, 21, 37), Comment = "I told my wife the truth. I told her I was seeing a psychiatrist. Then she told me the truth: that she was seeing a psychiatrist, two plumbers, and a bartender." }, new Entry { Name = "Mudpuppy", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 2, 19, 13, 46), Comment = "I'm always relieved when someone is delivering a eulogy and I realise I'm listening to it." }, new Entry { Name = "hedgehound", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 2, 19, 16, 23), Comment = "The human body was designed by a civil engineer. Who else would run a toxic waste pipeline through a recreational area?" }, new Entry { Name = "Ambrosaur", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 2, 20, 21, 59), Comment = "Sometimes I wonder if I really can. But then I think to myself, maybe I can't. But if I could, that would be good. Maybe it's all a lie?" }, new Entry { Name = "Caterwhy", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 2, 21, 57, 11), Comment = "I like to wax my legs and stick the hair on my back. Why? Because it keeps my back warm. There's method in my madness." }, new Entry { Name = "Ribbit Riot", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 3, 13, 8, 16), Comment = "Look! In the sky. It's a bird, it's a plane. Or is it a hellicopter? No actually I think it is a bird. Or maybe I'm just seeing things. Who knows... After 10 shots of Whiskey things start to get a bit strange." }, new Entry { Name = "CuckooBlue", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 3, 13, 27, 18), Comment = "People always told me be careful of what you do And dont go around breaking young girls' hearts And mother always told me be careful of who you love And be careful of what you do cause the lie becomes the truth." }, new Entry { Name = "ninja", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 3, 17, 52, 15), Comment = "Look! In the sky. It's a bird, it's a plane. Or is it a hellicopter? No actually I think it is a bird. Or maybe I'm just seeing things. Who knows... After 10 shots of Whiskey things start to get a bit strange." }, new Entry { Name = "Warewo", Email = "*****@*****.**", EntryTime = new DateTime(2021, 4, 3, 23, 12, 55), Comment = "Don't you find it Funny that after Monday(M) and Tuesday(T), the rest of the week says WTF?" } }); context.SaveChanges(); } }
public void AddEntry(GuestbookEntry entry) { entry.DateAdded = DateTime.Now; _db.Entries.Add(entry); _db.SaveChanges(); }
public ActionResult CreateMath(GuestbookMath entryMath, string action) { if (ModelState.IsValid) { switch (action) { case "+": { entryMath.TypeId = 1; entryMath.Total = new Functions().GetSum(entryMath.FirstNumber, entryMath.SecondNumber); _db.Maths.Add(entryMath); _db.SaveChanges(); log.Debug(entryMath.FirstNumber + " + " + entryMath.SecondNumber + " = " + entryMath.Total); GetLastValue(); break; } case "-": { entryMath.TypeId = 2; entryMath.Total = new Functions().GetMinus(entryMath.FirstNumber, entryMath.SecondNumber); _db.Maths.Add(entryMath); _db.SaveChanges(); GetLastValue(); break; } case "*": { entryMath.TypeId = 3; entryMath.Total = new Functions().GetMult(entryMath.FirstNumber, entryMath.SecondNumber); _db.Maths.Add(entryMath); _db.SaveChanges(); GetLastValue(); break; } case "/": { if (entryMath.SecondNumber == 0) { ViewBag.DerividZero = "Cannot dirived by zero"; } else { entryMath.TypeId = 4; entryMath.Total = new Functions().GetDerived(entryMath.FirstNumber, entryMath.SecondNumber); _db.Maths.Add(entryMath); _db.SaveChanges(); GetLastValue(); } break; } } } //GetLastValue(); //var list = _db.Maths.OrderByDescending(id => id.Id).Take(0); //ViewBag.List = list; //return View("CreateMath", lists.ToList()); return(View("CreateMath")); //return View(list.ToList()); }