Beispiel #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Name, 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();
                    //db.SaveChanges();

                    /*CSEBookBankDbEntities db = new CSEBookBankDbEntities();
                     * Librarian lib = new Librarian();
                     * lib.UserName = model.Name;
                     * lib.Password = model.Password;
                     * db.Librarians.Add(lib);*/

                    await UserManager.AddToRoleAsync(user.Id, "Student");

                    //MyRole role = new MyRole();
                    //role.UserId = user.Id;
                    //role.RoleId = 2.ToString();
                    //db.MyRoles.Add(role);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #2
0
 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 ActionResult IssueBook(int id)
        {
            string UsrName = User.Identity.GetUserName();
            Book   b       = new Book();

            b = db.Books.Find(id);
            String  title = b.Title;
            Request Rqst  = new Request();

            Rqst.RqstMessage = UsrName + " Wants to issue " + title + " " + id;
            Rqst.BookID      = b.BookID;
            Rqst.UserName    = UsrName;
            db.Requests.Add(Rqst);
            db.SaveChanges();
            return(RedirectToAction("index"));
        }
Beispiel #4
0
        public ActionResult BookRemoved(int id)
        {
            Book book = db.Books.Find(id);

            db.Books.Remove(book);
            db.SaveChanges();
            return(RedirectToAction("ViewBooks"));
        }
 public ActionResult AddBook([Bind(Include = "Title,Author,Edition,BookID,ImagePath,Description")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Books.Add(book);
         db.SaveChanges();
         return(RedirectToAction("ViewBooks"));
     }
     return(View());
 }
        public ActionResult IssueBook(int BookID)
        {
            string UsrName = User.Identity.GetUserName();
            Book   b       = new Book();

            b = db.Books.Find(BookID);
            String  title = b.Title;
            Request Rqst  = new Request();

            Rqst.RqstMessage = UsrName + " Wants to issue " + title + " " + BookID;
            Rqst.BookId      = b.BookID;
            Rqst.UserName    = UsrName;
            db.Requests.Add(Rqst);
            db.SaveChanges();
            return(View());
        }