public ActionResult AddBook([Bind(Include = "Title,Author,Edition,BookID,ImagePath")] Book book) { try { string filename = Path.GetFileNameWithoutExtension(book.ImageFile.FileName); string extension = Path.GetExtension(book.ImageFile.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; book.ImagePath = "~/Image/" + filename; filename = Path.Combine(Server.MapPath("~/Image"), filename); book.ImageFile.SaveAs(filename); using (CSEBookBankDbEntities db = new CSEBookBankDbEntities()) { if (db.Books.Any(x => x.Title == book.Title)) { ViewBag.DuplicateMessage = "CityName already exist."; return(View(book)); } db.Books.Add(book); db.SaveChanges(); } } catch (Exception ex) { return(View(ex)); } ModelState.Clear(); ViewBag.SuccessMessage = "Successful"; return(RedirectToAction("ViewBooks")); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.RegistrationNumber, Email = model.Email, Name = model.Name, RegistrationNumber = model.RegistrationNumber }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); CSEBookBankDbEntities db = new CSEBookBankDbEntities(); student std = new student(); std.UserName = model.Email; std.Password = model.Password; std.StudentName = model.Name; std.RegistrationNo = model.RegistrationNumber; db.students.Add(std); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult ViewBooks(int id) { Book book = new Book(); using (CSEBookBankDbEntities db = new CSEBookBankDbEntities()) { book = db.Books.Where(x => x.BookID == id).FirstOrDefault(); } return(View(book)); }