public ActionResult AddBookofStudent(int id) { LoadnedVM oduncModel = new LoadnedVM(); oduncModel.BookID = id; oduncModel.Students = new SelectList(_db.Students.ToList(), "Id", "Email"); if (_db.Books.Find(id).Count > 0) { _db.Books.Find(id).IsActive = true; return(View(oduncModel)); } else { ViewData["ErrorMessage"] = "İstenilen kitap stokta bulunmamaktadır."; return(View(oduncModel)); } }
public ActionResult CAddBookofStudent(LoadnedVM model) { Book_Student entity = new Book_Student(); if (ModelState.IsValid) { entity.StudentID = model.StudentID; entity.BookID = model.BookID; entity.LoadnedStartDate = model.LoadnedStartDate; entity.LoanedEndDate = model.loadnedEndDate; entity.Price = Convert.ToInt32(10); entity.Control = true; entity.DEPT = Convert.ToInt32(0); Book en = _db.Books.Find(entity.BookID); int sayi = en.Count; sayi--; en.Count = sayi; if (en.Count == 0) { en.IsActive = false; } else { en.IsActive = true; } var getir = _db.Book_Student.FirstOrDefault(p => p.StudentID == model.StudentID && p.BookID == model.BookID && p.Control == true); if (getir != null) { ViewData["Error"] = "İstenilen kitap zaten bu öğrencide var."; return(View()); } _db.Book_Student.Add(entity); _db.SaveChanges(); var bugun = DateTime.Now.Day; if (bugun > entity.LoanedEndDate.Value.Day) { MailMessage mail = new MailMessage(); mail.To.Add(_db.Book_Student.FirstOrDefault(x => x.StudentID == model.StudentID).Student.Email); mail.From = new MailAddress("*****@*****.**"); mail.Subject = "kitap iade süresi gecikmesi"; string Body = "kitabınız " + (bugun - entity.LoanedEndDate.Value.Day) + "gün gecikmiştir iade ediniz.günlük borcunuz 10 tl dir"; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential ("kutuphanesistemi", "temmuz2016"); smtp.EnableSsl = true; smtp.Send(mail); } return(RedirectToAction("Index", "Book")); } else { return(View()); } }