예제 #1
0
        public ActionResult Create([Bind(Include = "Id,UserId,BookId,GuardianName,GuardianSurname,GuardianID,GuardianCell,GuardianAddress,HasPenalty,DateOfRent,DateOfReturn,ExpectedDate")] Rental rental)
        {
            var rented = db.Rentals.Where(x => x.BookId == rental.BookId).FirstOrDefault();

            ViewBag.BookId = new SelectList(db.Books, "Id", "Title", rental.BookId);
            ViewBag.UserId = new SelectList(db.Users, "UserId", "FirstName", rental.UserId);

            if (rented != null)
            {
                ViewBag.SetMessage = $"Sorry book has already been rented, from {rented.DateOfRent} till {rented.DateOfReturn}";
                return(View());
            }
            else
            {
                if (ModelState.IsValid)
                {
                    db.Rentals.Add(rental);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }


                return(View(rental));
            }
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "Id,RoleName")] Role role)
        {
            if (ModelState.IsValid)
            {
                db.Roles.Add(role);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
예제 #3
0
        public ActionResult Create([Bind(Include = "id,Type,Description")] InstitutionType institutionType)
        {
            if (ModelState.IsValid)
            {
                db.InstitutionTypes.Add(institutionType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(institutionType));
        }
예제 #4
0
        public ActionResult Create([Bind(Include = "Id,Condition1")] Condition condition)
        {
            if (ModelState.IsValid)
            {
                db.Conditions.Add(condition);
                db.SaveChanges();
                TempData["successMessage"] = $"Book Condition successfully added";
                return(RedirectToAction("Index"));
            }

            return(View(condition));
        }
        public ActionResult Create([Bind(Include = "Id,Category1,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                TempData["successMessage"] = $"Book Category successfully added";
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
 public ActionResult Edit([Bind(Include = "UserId,FirstName,LastName,Email,ID_Number,Address,Phone,GenderId,InstitutionId,Password,IsEmailVerified,ActivationCode,ForrgotPasswordCode")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GenderId      = new SelectList(db.Genders, "Id", "Gender1", user.GenderId);
     ViewBag.InstitutionId = new SelectList(db.Institutions, "Id", "Name", user.InstitutionId);
     return(View(user));
 }
        public ActionResult Create([Bind(Include = "Id,Name,Address,Email,InstitutionId")] Campus campus)
        {
            if (ModelState.IsValid)
            {
                db.Campus1.Add(campus);
                TempData["successMessage"] = $"Campus successfully added";
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.InstitutionId = new SelectList(db.Institutions, "Id", "Name", campus.InstitutionId);
            return(View(campus));
        }
예제 #8
0
        public ActionResult Create([Bind(Include = "Id,Name,Email,CampusId")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                TempData["successMessage"] = $"Department successfully Added";
                return(RedirectToAction("Index"));
            }

            ViewBag.CampusId = new SelectList(db.Campus1, "Id", "Name", department.CampusId);
            return(View(department));
        }
예제 #9
0
        public ActionResult Create([Bind(Include = "Id,Name,LastName,StudentNumber,Email,PhoneNumber,GenderId,Address,InstitutionId,IdentityNumber,Password,DOB")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.GenderId      = new SelectList(db.Genders, "Id", "Gender1", student.GenderId);
            ViewBag.InstitutionId = new SelectList(db.Institutions, "Id", "Name", student.InstitutionId);
            return(View(student));
        }
예제 #10
0
        public ActionResult Create([Bind(Include = "Id,Name,TypeId")] Institution institution)
        {
            if (ModelState.IsValid)
            {
                db.Institutions.Add(institution);
                db.SaveChanges();
                TempData["successMessage"] = $"Institution successfully Added";
                return(RedirectToAction("Index"));
            }

            ViewBag.TypeId = new SelectList(db.InstitutionTypes, "id", "Type", institution.TypeId);
            return(View(institution));
        }
        public ActionResult ForgotPassword(string email)
        {
            string message = "";
            bool   status  = false;

            if (string.IsNullOrEmpty(email))
            {
                message = "Error: Email is a required field!";
            }
            else
            {
                using (BookAppDbEntities db = new BookAppDbEntities())
                {
                    var account = db.Users.Where(a => a.Email == email).FirstOrDefault();
                    if (account != null)
                    {
                        string resetCode = Guid.NewGuid().ToString();
                        SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword");
                        account.ResetPasswordCode = resetCode;
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        message = "Reset password link has been sent to your email id.";
                    }
                    else
                    {
                        message = "Account not found";
                    }
                }
            }

            ViewBag.Message = message;
            return(View());
        }
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (BookAppDbEntities dc = new BookAppDbEntities())
                {
                    var user = dc.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.Password          = Crypto.Hash(model.NewPassword);
                        user.ResetPasswordCode = "";
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "New password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something invalid";
            }
            ViewBag.Message = message;
            return(View(model));
        }
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            ViewBag.GenderId      = new SelectList(db.Genders, "Id", "Gender1", user.GenderId);
            ViewBag.InstitutionId = new SelectList(db.Institutions, "Id", "Name", user.InstitutionId);


            if (ModelState.IsValid)
            {
                #region //Email is already Exist
                var isExist = DoesEmailExist(user.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View());
                }


                #endregion

                #region Generate Activation Code
                user.ActivationCode = Guid.NewGuid();
                #endregion

                #region  Password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); //
                #endregion
                user.IsEmailVerified = false;

                #region Save to Database
                using (BookAppDbEntities db = new BookAppDbEntities())
                {
                    db.Users.Add(user);
                    db.SaveChanges();

                    SendVerificationLinkEmail(user.Email, user.ActivationCode.ToString());
                    message = " Registration successfully done. Account activation link " +
                              " has been sent to your email: " + user.Email + "\nKindly click on the link to activate your account.\n" +
                              " BookApp2020";
                    Status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;

            return(View(user));
        }
        public ActionResult Create(Book book)
        {
            string fileName  = Path.GetFileNameWithoutExtension(book.ImageFile.FileName);
            string extension = Path.GetExtension(book.ImageFile.FileName);

            fileName   = fileName + DateTime.Now.ToString("yymmssfff") + extension;
            book.Image = "~/Image/" + fileName;
            fileName   = Path.Combine(Server.MapPath("~/Image/"), fileName);
            book.ImageFile.SaveAs(fileName);

            using (BookAppDbEntities bookDb = new BookAppDbEntities())
            {
                if (ModelState.IsValid)
                {
                    db.Books.Add(book);
                    TempData["successMessage"] = $"Book successfully added";
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(" ", "Error: Please fill in all the fields!");
                }
            }


            ModelState.Clear();

            ViewBag.CategoryId    = new SelectList(db.Categories, "Id", "Category1", book.CategoryId);
            ViewBag.ConditionId   = new SelectList(db.Conditions, "Id", "Condition1", book.ConditionId);
            ViewBag.InstitutionId = new SelectList(db.Institutions, "Id", "Name", book.InstitutionId);
            return(View(book));
        }
        public ActionResult Create([Bind(Include = "Id,Gender1")] Gender gender)
        {
            if (ModelState.IsValid)
            {
                string returnMessage = "";

                if (string.IsNullOrEmpty(gender.Gender1))
                {
                    ViewBag.Message = "Error: Field cannot be empty!";
                    return(View());
                }
                else
                {
                    db.Genders.Add(gender);
                    db.SaveChanges();
                    TempData["successMessage"] = $"Gender successfully Added";
                    return(RedirectToAction("Index"));
                }
            }

            return(View(gender));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,Name,Surname,Phone,Email,Subject,Enquiry,Address,BookId,AllowSeller")] Seller seller)
        {
            if (ModelState.IsValid)
            {
                string emailMessage = $"Dear " + seller.Email + " ,<br/>" +
                                      "<br/> This is email servers to inform you that user : <br/><br/>" + "<b>" + seller.Name + "<b/>" + " " + seller.Surname
                                      + "<br/> Phone number: " + seller.Phone + "<br/> might be having an interest in purchasing your book<br/><br/>" +
                                      "" +
                                      "The user left this message below:<br/><br/>" + "<i>" + seller.Enquiry + "<i/>" + "<br/><br/>Kind regards</br><br/><b>Book App 2020 Team<b/>";

                string emailSubj = EmaiInfo.EMAIL_SUBJECT_DEFAULT;

                await this.SendEmailAsync(seller.Email, emailMessage, emailSubj);

                // return this.Json(new { EnableSuccess = true, SuccessTitle = "Success", SuccessMsg = "Notification sent successful" });

                db.Sellers.Add(seller);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BookId = new SelectList(db.Books, "Id", "Title", seller.BookId);
            return(View(seller));
        }
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (BookAppDbEntities dc = new BookAppDbEntities())
            {
                dc.Configuration.ValidateOnSaveEnabled = false;
                var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }