public ActionResult AddBook(Book book) { using (var db = new KutuphaneDbContext()) { if (book == null) { return(HttpNotFound()); } db.Books.Add(book); db.SaveChanges(); return(RedirectToAction("Books")); } }
public ActionResult AddWriter(Writer writer) { using (var db = new KutuphaneDbContext()) { if (writer == null) { return(HttpNotFound()); } db.Writers.Add(writer); db.SaveChanges(); return(RedirectToAction("Writers")); } }
public ActionResult AddMember(Member member) { using (var db = new KutuphaneDbContext()) { if (member == null) { return(HttpNotFound()); } db.Members.Add(member); db.SaveChanges(); return(RedirectToAction("Members")); } }
public ActionResult RecieveBook(int id) { using (var db = new KutuphaneDbContext()) { var borrow = db.Borrows.Find(id); if (borrow == null) { return(HttpNotFound()); } borrow.ReturnDate = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Borrows")); } }
public ActionResult DeleteBorrow(int id) { using (var db = new KutuphaneDbContext()) { var borrow = db.Borrows.Find(id); if (borrow == null) { return(HttpNotFound()); } db.Borrows.Remove(borrow); db.SaveChanges(); return(RedirectToAction("Borrows")); } }
public ActionResult EditBookType(BookType booktype) { using (var db = new KutuphaneDbContext()) { var bt = db.BookTypes.Find(booktype.Id); if (bt == null) { return(HttpNotFound()); } bt.Name = booktype.Name; bt.Explanation = booktype.Explanation; db.SaveChanges(); return(RedirectToAction("BookTypes")); } }
public ActionResult DeleteBook(int id) { using (var db = new KutuphaneDbContext()) { var book = db.Books.Find(id); if (book == null) { return(HttpNotFound()); } var borrows = db.Borrows.Where(x => x.BookId == id).ToList(); db.Borrows.RemoveRange(borrows); db.Books.Remove(book); db.SaveChanges(); return(RedirectToAction("Books")); } }
public ActionResult DeleteMember(int id) { using (var db = new KutuphaneDbContext()) { var member = db.Members.Find(id); if (member == null) { return(HttpNotFound()); } var borrows = db.Borrows.Where(x => x.MemberId == id).ToList(); db.Borrows.RemoveRange(borrows); db.Members.Remove(member); db.SaveChanges(); return(RedirectToAction("Members")); } }
public ActionResult EditWriter(Writer writer) { using (var db = new KutuphaneDbContext()) { var wr = db.Writers.Find(writer.Id); if (wr == null) { return(HttpNotFound()); } wr.NameSurname = writer.NameSurname; wr.BirthDate = writer.BirthDate; wr.Biography = writer.Biography; db.SaveChanges(); return(RedirectToAction("Writers")); } }
public ActionResult EditBorrow(Borrow borrow) { using (var db = new KutuphaneDbContext()) { var bw = db.Borrows.FirstOrDefault(x => x.Id == borrow.Id); if (bw == null) { return(HttpNotFound()); } bw.MemberId = borrow.MemberId; bw.ReturnDate = borrow.ReturnDate; bw.EstimatedReturnDate = borrow.EstimatedReturnDate; bw.BorrowDate = borrow.BorrowDate; bw.BookId = borrow.BookId; db.SaveChanges(); return(RedirectToAction("Borrows")); } }
public ActionResult EditMember(Member member) { using (var db = new KutuphaneDbContext()) { var mb = db.Members.FirstOrDefault(x => x.Id == member.Id); if (mb == null) { return(HttpNotFound()); } mb.Adress = member.Adress; mb.BirthDate = member.BirthDate; mb.BirthPlace = member.BirthPlace; mb.EMail = member.EMail; mb.MembershipStartDate = member.MembershipStartDate; mb.NameSurname = member.NameSurname; mb.SSN = member.SSN; mb.TelephoneNumber = member.TelephoneNumber; db.SaveChanges(); return(RedirectToAction("Members")); } }
public ActionResult DeleteBookType(int id) { using (var db = new KutuphaneDbContext()) { var booktype = db.BookTypes.Find(id); if (booktype == null) { return(HttpNotFound()); } var books = db.Books.Where(x => x.TypeId == id).ToList(); foreach (Book book in books) { var borrows = db.Borrows.Where(x => x.BookId == book.Id).ToList(); db.Borrows.RemoveRange(borrows); } db.Books.RemoveRange(books); db.BookTypes.Remove(booktype); db.SaveChanges(); return(RedirectToAction("BookTypes")); } }
public ActionResult EditBook(Book book) { using (var db = new KutuphaneDbContext()) { var bk = db.Books.FirstOrDefault(x => x.Id == book.Id); if (bk == null) { return(HttpNotFound()); } bk.BookType = book.BookType; bk.ISBN = book.ISBN; bk.Name = book.Name; bk.PageNumber = book.PageNumber; bk.Price = book.Price; bk.Publisher = book.Publisher; bk.Summary = book.Summary; bk.TypeId = book.TypeId; bk.WriterId = book.WriterId; db.SaveChanges(); return(RedirectToAction("Books")); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); using (var context = new KutuphaneDbContext()) { context.Database.Initialize(false); if (context.Users.Count() == 0) { context.Users.Add(new User() { Username = "******", Password = "******" }); context.SaveChanges(); } if (context.Writers.Count() == 0) { for (int i = 0; i < 15; i++) { context.Writers.Add(new Writer() { Biography = "bibibiibibibib", BirthDate = DateTime.Now.AddYears(-25), NameSurname = RandomString(5) + " " + RandomString(6) }); } } if (context.BookTypes.Count() == 0) { for (int i = 0; i < 15; i++) { context.BookTypes.Add(new BookType() { Explanation = "epxepxpepxpe", Name = RandomString(8) }); } } context.SaveChanges(); if (context.Books.Count() == 0) { for (int i = 0; i < 50; i++) { context.Books.Add(new Book() { TypeId = context.BookTypes.ToList().Skip(random.Next(0, 14)).First().Id, ISBN = RandomString(15), Name = RandomString(6), PageNumber = random.Next(100, 600), Price = random.Next(20, 70), Publisher = RandomString(8), Summary = RandomString(120), WriterId = context.Writers.ToList().Skip(random.Next(0, 13)).First().Id, }); } } context.SaveChanges(); if (context.Members.Count() == 0) { for (int i = 0; i < 15; i++) { context.Members.Add(new Member() { SSN = RandomString(15), NameSurname = RandomString(6) + " " + RandomString(6), BirthDate = DateTime.Now.AddYears(-40), BirthPlace = RandomString(10), MembershipStartDate = DateTime.Now.AddYears(-25), Adress = RandomString(35), TelephoneNumber = RandomString(12), EMail = RandomString(10) + "@" + RandomString(5) + ".com", }); } } context.SaveChanges(); if (context.Borrows.Count() == 0) { for (int i = 0; i < 15; i++) { context.Borrows.Add(new Borrow() { BorrowDate = DateTime.Now.AddYears(-30), EstimatedReturnDate = DateTime.Now.AddYears(-29), BookId = context.Books.ToList().Skip(random.Next(0, 50)).First().Id, ReturnDate = DateTime.Now.AddMonths(-5), MemberId = context.Members.ToList().Skip(random.Next(0, 14)).First().Id, }); } } context.SaveChanges(); } }