public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities())
                {
                    var user = db.Users.Where(a => a.resetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        //user.Password = Crypto.Hash(model.NewPassword);
                        //user.password = md5(model.NewPassword);
                        user.password          = Encrypt(model.NewPassword);
                        user.resetPasswordCode = "";
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        message = "Cập nhật mật khẩu mới thành công!";
                    }
                }
            }
            else
            {
                message = "Bạn phải nhật mật khẩu và xác nhận lại mật khẩu!";
            }
            ViewBag.Message = message;
            return(View(model));
        }
        public ActionResult Index(string EmailID)
        {
            //Verify Email ID
            //Generate Reset password link
            //Send Email
            string message = "";
            bool   status  = false;

            using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities())
            {
                var account = db.Users.Where(a => a.username == EmailID).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.username, resetCode, "ResetPassword");
                    account.resetPasswordCode = resetCode;
                    //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property
                    //in our model class in part 1
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                    message = "Link lấy lại mật khẩu đã được gửi vào email của bạn!";
                }
                else
                {
                    message = "Tài khoản không tìm thấy!";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
Ejemplo n.º 3
0
        public IHttpActionResult SaveTime(Model model)
        {
            var ebook    = db.Ebooks.Where(x => x.ebook_id == model.BookId).Select(x => x.title).FirstOrDefault();
            var essay    = db.Essays.Where(x => x.essay_id == model.BookId).Select(x => x.title).FirstOrDefault();
            var thesis   = db.Theses.Where(x => x.thesis_id == model.BookId).Select(x => x.title).FirstOrDefault();
            var bookname = "";

            if (ebook != null)
            {
                bookname = ebook;
            }
            if (essay != null)
            {
                bookname = essay;
            }
            if (thesis != null)
            {
                bookname = thesis;
            }
            db.Times.Add(new Time
            {
                userid   = model.UserId,
                bookid   = model.BookId,
                bookname = bookname,
                time1    = model.Time,
                date     = DateTime.Now,
                sub_id   = model.SubId
            });
            db.SaveChanges();
            return(Ok());
        }
Ejemplo n.º 4
0
        public string CreateSubject(SubjectViewModel subject)
        {
            var sub = db.Subject_Ebook.Where(x => x.name.Equals(subject.Name)).FirstOrDefault();

            if (sub != null)
            {
                return("Tên môn đã tồn tại! Vui lòng đặt tên khác.");
            }
            else
            {
                db.Subject_Ebook.Add(new Subject_Ebook
                {
                    name = subject.Name,
                });
                db.SaveChanges();
                var sub_ebook = db.Subject_Ebook.Where(x => x.name.Equals(subject.Name)).FirstOrDefault();

                //MyHub.Post(sub_ebook.id, sub_ebook.name);
            }
            return("Tạo môn thành công.");
        }
        public ChangePassModel ChangePass(PassInfo model)
        {
            //model.passOld = md5(model.passOld);
            model.passOld = Encrypt(model.passOld);
            var user = db.Users.Where(x => x.username == model.email && x.password == model.passOld).FirstOrDefault();

            if (user != null)
            {
                //user.password = md5(model.passNew);
                user.password = Encrypt(model.passNew);
                db.SaveChanges();
                return(new ChangePassModel {
                    IsSuccess = true,
                    Message = "Đổi mật khẩu thành công!"
                });
            }
            return(new ChangePassModel
            {
                IsSuccess = false,
                Message = "Đổi mật khẩu thất bại!"
            });
        }
Ejemplo n.º 6
0
        public SubjectCreationResult CreateSubject(SubjectViewModel subject)
        {
            var sub = db.Subject_Essay.Where(x => x.name.Equals(subject.Name.Trim()) ||
                                             x.subessay_id.Equals(subject.Subessay_Id.Trim())).FirstOrDefault();

            if (sub != null)
            {
                return(new SubjectCreationResult
                {
                    IsSuccess = false
                });
            }
            else
            {
                db.Subject_Essay.Add(new Subject_Essay
                {
                    subessay_id = subject.Subessay_Id.Trim(),
                    name        = subject.Name,
                });
                db.SaveChanges();
                // var sub_essay = db.Subject_Essay.Where(x => x.name.Equals(subject.Name)).FirstOrDefault();
                //var sub_essay = db.Subject_Essay.OrderByDescending(x => x.id).Take(1).FirstOrDefault();
                var sub_essay   = db.Subject_Essay.Where(x => x.subessay_id == subject.Subessay_Id).FirstOrDefault();
                var subessay_id = db.Subject_Essay.Where(x => x.id == sub_essay.id).Select(x => x.subessay_id).FirstOrDefault();

                return(new SubjectCreationResult
                {
                    IsSuccess = true,
                    Id = sub_essay.id,
                    Subessay_Id = subessay_id,
                    Name = sub_essay.name
                });
            }
        }
        public SubjectCreationResult EditSubjectById(Subject_Ebook subject)
        {
            var check = db.Subject_Ebook.Where(x => x.id == subject.id).FirstOrDefault();

            if (check == null)
            {
                return(new SubjectCreationResult
                {
                    IsSuccess = false
                });
            }
            else
            {
                var sub = db.Subject_Ebook.Where(x => (x.id != subject.id) &&
                                                 (x.subebook_id == subject.subebook_id || x.name == subject.name)).FirstOrDefault();
                if (sub != null)
                {
                    return(new SubjectCreationResult
                    {
                        IsSuccess = false
                    });
                }
                else
                {
                    check.subebook_id = subject.subebook_id;
                    check.name        = subject.name;
                    db.SaveChanges();
                    return(new SubjectCreationResult
                    {
                        IsSuccess = true,
                        Subebook_Id = check.subebook_id,
                        Name = check.name,
                    });
                }
            }


            //var sub = db.Subject_Ebook.Where(x => x.id == subject.id).FirstOrDefault();

            //if (sub == null)
            //{
            //    return new SubjectCreationResult
            //    {
            //        IsSuccess = false
            //    };
            //}
            //else
            //{
            //    sub.subebook_id = subject.subebook_id;
            //    sub.name = subject.name;
            //    db.SaveChanges();
            //    return new SubjectCreationResult
            //    {
            //        IsSuccess = true,
            //        Subebook_Id = sub.subebook_id,
            //        Name = sub.name,

            //    };
            //}
        }
Ejemplo n.º 8
0
        public string UploadFiles()
        {
            var httpPostedFile = HttpContext.Current.Request.Files["fileInput"];//lấy file

            if (httpPostedFile != null)
            {
                //đường dẫn lưu file
                //string temp = RandomString(10, true) + "-";
                var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/Upload/"), httpPostedFile.FileName);//tên file
                //lưu file vào đường dẫn
                httpPostedFile.SaveAs(fileSavePath);
            }

            var    title        = HttpContext.Current.Request["title"];
            var    describe     = HttpContext.Current.Request["describe"];
            var    author       = HttpContext.Current.Request["author"];
            var    year         = HttpContext.Current.Request["year"];
            var    userid       = HttpContext.Current.Request["userid"];
            var    subid        = HttpContext.Current.Request["subid"];
            var    date_upload  = DateTime.Now;
            int    user_id      = Convert.ToInt32(userid);
            int    sub_id       = Convert.ToInt32(subid);
            string strExtexsion = Path.GetExtension(httpPostedFile.FileName).Trim();//lấy đuôi file
            string a            = "";

            if (strExtexsion == ".pdf")//chỉ cho up pdf
            {
                string temp = RandomString(10, true) + "-";
                using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities())
                {
                    //Add vô bảng ebook
                    db.Ebooks.Add(
                        new Ebook
                    {
                        ebook_id    = "",
                        title       = title,
                        describe    = describe,
                        author      = author,
                        year        = year,
                        filename    = httpPostedFile.FileName,
                        date_upload = date_upload,
                        user_id     = user_id,
                        sub_id      = sub_id,
                    });
                    db.SaveChanges();//lưu dât thôi cái này t chưa chạy t mới test gửi data từ  ajax qua thôi
                    var user     = db.Users.Where(x => x.id == user_id).Select(x => x.username).FirstOrDefault();
                    var subject  = db.Subject_Ebook.Where(x => x.id == sub_id).Select(x => x.name).FirstOrDefault();
                    var fileinfo = db.Ebooks.OrderByDescending(x => x.id).FirstOrDefault();
                    var date_up  = date_upload.ToString("MM/dd/yyyy");
                    MyHub.PostFileEbook(fileinfo.id, fileinfo.title, fileinfo.author, fileinfo.describe,
                                        fileinfo.year, fileinfo.filename, date_up, user, subject);
                    a = "Thành công";
                }
            }
            else
            {
                a = "lỗi";
            }

            return(a);
        }