// GET: Member/AddBook public ActionResult Index(int IdBook) { int IdReader = SessionUtils.ConnectedUser.IdReader; DateTime today = DateTime.Today; BookReservationRepository BR = new BookReservationRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); BookCopyRepository Bcr = new BookCopyRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); int nbBookAvailable = Bcr.getNbBookCopy(IdBook); if (nbBookAvailable == 0) { SessionUtils.ErrorReservation = "We couldn't save this book to you! No copy of this book available for the moment."; return(RedirectToAction("Index", new { controller = "Home", area = "" })); } else { int IdBookCopyReserved = BR.InsertWithBook(SessionUtils.ConnectedUser.IdReader, IdBook, today); BookRepository br = new BookRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); Book B = br.GetOne(IdBook); BookModel Bm = MapToDbModels.BookToBookModel(B); return(View(Bm)); } }
public ActionResult Edit(int id) { ReaderRepository Rr = new ReaderRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); Reader R = Rr.GetOne(id); ProfileModel Pm = MapToDbModels.ReaderToProfile(R); return(View(Pm)); }
public ViewResult Register(RegisterModel Rm, HttpPostedFileBase ProfilePicture) { List <string> matchContentType = new List <string>() { "image/jpeg", "image/png", "image/gif" }; if (!matchContentType.Contains(ProfilePicture.ContentType) || ProfilePicture.ContentLength > 80000) { ViewBag.ErrorMessage = "You can upload a file with the following exctentions(png, jpg, gif)"; return(View()); } if (!ModelState.IsValid) { foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { ViewBag.ErrorMessage += error.ErrorMessage + "<br>"; } } } else { // insert the new reader ReaderRepository Rr = new ReaderRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); Reader R = Rr.Insert(MapToDbModels.RegisterToReader(Rm)); if (R != null) { //saving the picture string[] splitFileName = ProfilePicture.FileName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); string ext = splitFileName[splitFileName.Length - 1]; string newFileName = R.Id + "." + ext; string folderpath = Server.MapPath("~/Photos/"); string FileNameToSave = folderpath + "/" + newFileName; try { ProfilePicture.SaveAs(FileNameToSave); } catch (Exception) { ViewBag.ErrorMessage = "The image couldn't be saved"; } } else { ViewBag.ErrorMessage = "Error during Insertion"; } } return(View("Login")); }
public ActionResult Search(string txtSearch) { BookRepository BR = new BookRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); List <BookModel> Lbm = BR.GetFromSearch(txtSearch).Select(b => MapToDbModels.BookToBookModel(b)).ToList(); if (Lbm.Count() == 0) { ViewBag.ErrorMessage = "Sorry, we couldn't find the book you were looking for!"; return(View()); } return(View(Lbm)); }
public ActionResult Edit(EditProfile Ep) { ReaderRepository Rr = new ReaderRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); Reader R = MapToDbModels.EditReader(Ep); if (Rr.Update(R)) { return(RedirectToAction("Index")); } else { return(View()); } }
public ActionResult Index(int id = 1) { ViewBag.CurrentPage = id; BookRepository BR = new BookRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); //List<BookModel> Lbm = BR.GetAll().Select(b => MapToDbModels.BookToBookModel(b)).ToList(); int nb = BR.getNbBooks(); //Book book = BR.getBookFromApi(); List <BookModel> Lbm = BR.Paginate(id, 8).Select(b => MapToDbModels.BookToBookModel(b)).ToList(); ViewBag.MaxPages = Math.Round((double)BR.getNbBooks() / 8); return(View(Lbm)); }
public ActionResult Login(LoginModel m) { ReaderRepository Rr = new ReaderRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); ProfileModel Mmodel = MapToDbModels.ReaderToProfile(Rr.VerifLogin(MapToDbModels.LoginToReader(m))); if (Mmodel != null) { SessionUtils.ConnectedUser = Mmodel; SessionUtils.IsConnected = true; return(RedirectToAction("Index", new { controller = "Home", area = "Member" })); } else { ViewBag.ErrorLoginMessage = "Erreur Login/ Password"; return(View()); } }
// GET: Member/Book public ActionResult Index() { ViewBag.Current = "Books"; BookRepository BR = new BookRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); List <BookMemberModel> Bm = BR.GetBooksFromReader(SessionUtils.ConnectedUser.IdReader).Select(b => MapToDbModels.BookToBookMemberModel(b)).ToList(); if (Bm.Count() == 0) { ViewBag.NoBooks = "There are no books in your account!"; return(View()); } return(View(Bm)); }