public ActionResult Lecture(int?id, int?cpage)
        {
            using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
            {
                var lecture = unitofwork.Lectures.FirstOrDefault(x => x.Id == id);
                if (!CookiesManage.Logined())
                {
                    return(View(lecture));
                }
                {
                    var user           = CookiesManage.GetUser();
                    var studentSubject = unitofwork.StudentSubjects
                                         .FirstOrDefault(x => x.Username.ToLower() == user.Username.ToLower() &&
                                                         x.SubjectId == lecture.SubjectId);

                    if (studentSubject != null)
                    {
                        var lectures = unitofwork.Lectures.Query(x => x.SubjectId == lecture.SubjectId).ToList();
                        ViewBag.Lectures = lectures;
                        ViewBag.IsReg    = true;
                        ViewBag.Status   = studentSubject.Status;

                        ///Show comment
                        ViewBag.Comments = GetComment(cpage);
                    }
                    else
                    {
                        ViewBag.IsReg = false;
                    }
                }
                return(View(lecture));
            }
        }
        // GET: Account
        public ActionResult Index()
        {
            if (!CookiesManage.Logined())
            {
                return(RedirectToAction("Login", "Account"));
            }

            using (var workScope = new UnitOfWork(new PatientManagementDbContext()))
            {
                var user    = CookiesManage.GetUser();
                var patient = workScope.Patients.FirstOrDefault(x => x.Id == user.PatientId);

                if (patient != null)
                {
                    var record = workScope.Records.FirstOrDefault(x => x.Id == patient.RecordId);
                    record.Doctor   = workScope.Doctors.FirstOrDefault(x => x.Id == record.DoctorId);
                    ViewBag.Record  = record;
                    ViewBag.Patient = patient;

                    var detailRecord = workScope.DetailRecords
                                       .Query(x => x.RecordId == record.Id)
                                       .OrderByDescending(x => x.Process).ToList();
                    return(View(detailRecord));
                }
                else
                {
                    return(RedirectToAction("E404", "Home"));
                }
            }
        }
예제 #3
0
        // GET: Account
        public ActionResult Index(int?page)
        {
            if (!CookiesManage.Logined())
            {
                return(RedirectToAction("Login", "Account"));
            }

            using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
            {
                var user = CookiesManage.GetUser();

                //Lấy danh sách khóa học được user hiện tại đăng ký
                var listCourseReg = unitofwork.StudentSubjects.GetAll().Where(x => x.Username == user.Username);

                Expression <Func <Subject, object> >[] includes = new Expression <Func <Subject, object> > [1];
                includes[0] = x => x.Course;

                var subjects = unitofwork.Subjects.Include(includes);

                var listData = from cReg in listCourseReg
                               join s in subjects on cReg.SubjectId equals s.Id
                               select s;

                int pageNumber = (page ?? 1);
                int pageSize   = 4;
                return(View(listData.ToPagedList(pageNumber, pageSize)));
            }
        }
 public ActionResult Login(string returnUrl = "")
 {
     if (CookiesManage.Logined())
     {
         return(RedirectToAction("Index", "Account"));
     }
     ViewBag.ReturnUrl = returnUrl;
     return(View());
 }
예제 #5
0
 public ActionResult Index(string returnUrl = "")
 {
     if (CookiesManage.Logined())
     {
         return(RedirectToAction("Index", "Dashboard"));
     }
     ViewBag.ReturnUrl = returnUrl;
     return(View());
 }
예제 #6
0
 // GET: /Administrator/Base/
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (!CookiesManage.Logined())
     {
         var returnUrl = filterContext.HttpContext.Request.RawUrl;
         filterContext.Result =
             new RedirectResult(string.Concat("~/Doctor/Login/Index", "?ReturnUrl=", returnUrl));
     }
     base.OnActionExecuting(filterContext);
 }
예제 #7
0
 public JsonResult Del(int role, int id)
 {
     if (CookiesManage.GetUser().RoleId != RoleKey.Admin)
     {
         return(Json(new { status = false, mess = "Bạn không có quyền" }));
     }
     try
     {
         if (role == RoleKey.Teacher)
         {
             using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
             {
                 var elm = unitofwork.TeacherSubjects.Get(id);
                 if (elm != null)
                 {
                     unitofwork.TeacherSubjects.Remove(elm);
                     unitofwork.Complete();
                     return(Json(new { status = true, mess = "Xóa thành công " }));
                 }
                 else
                 {
                     return(Json(new { status = false, mess = "Không tồn tại " }));
                 }
             }
         }
         else if (role == RoleKey.Student)
         {
             using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
             {
                 var elm = unitofwork.StudentSubjects.Get(id);
                 if (elm != null)
                 {
                     unitofwork.StudentSubjects.Remove(elm);
                     unitofwork.Complete();
                     return(Json(new { status = true, mess = "Xóa thành công " }));
                 }
                 else
                 {
                     return(Json(new { status = false, mess = "Không tồn tại " }));
                 }
             }
         }
         else
         {
             return(Json(new { status = false, mess = "Bạn không có quyền" }));
         }
     }
     catch
     {
         return(Json(new { status = false, mess = "Thất bại" }));
     }
 }
예제 #8
0
        public JsonResult Rate(int courseId, double point)
        {
            if (CookiesManage.Logined())
            {
                if (courseId >= 1 && RateKey.Any(point))
                {
                    using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
                    {
                        var user   = CookiesManage.GetUser();
                        var course = unitofwork.Courses.FirstOrDefault(x => x.Id == courseId);
                        if (course != null)
                        {
                            var rating = unitofwork.Rating.FirstOrDefault(x => x.CourseId == courseId && x.Username == user.Username);

                            if (rating != null)
                            {
                                rating.Point = point;
                                unitofwork.Rating.Put(rating, rating.Id);
                            }
                            else
                            {
                                var rate = new Rating
                                {
                                    CourseId = course.Id,
                                    Username = CookiesManage.GetUser().Username,
                                    Point    = point
                                };
                                unitofwork.Rating.Add(rate);
                            }

                            unitofwork.Complete();
                            //xóa thành công
                            return(Json(new { status = true, mess = $"Bạn đã xếp hạng: {point} sao cho khóa học: {course.Name}" }));
                        }
                        else
                        {
                            return(Json(new { status = false, mess = "course không tồn tại" }));
                        }
                    }
                }
                else
                {
                    return(Json(new { status = false, mess = "Lỗi dữ liệu" }));
                }
            }
            else
            {
                return(Json(new { status = false, mess = "Vui lòng đăng nhập" }));
            }
        }
        public ActionResult Edit()
        {
            if (!CookiesManage.Logined())
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                var user = CookiesManage.GetUser();

                using (var workScope = new UnitOfWork(new PatientManagementDbContext()))
                {
                    var account = workScope.Accounts.GetAll().Where(x => x.UserName.Trim().ToLower() == user.UserName.Trim().ToLower());
                    return(View(account));
                }
            }
        }
예제 #10
0
        public ActionResult Edit()
        {
            if (!CookiesManage.Logined())
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                var user = CookiesManage.GetUser();

                using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
                {
                    var account = unitofwork.Account.GetAll().Where(x => x.Username.Trim().ToLower() == user.Username.Trim().ToLower());
                    return(View(account));
                }
            }
        }
예제 #11
0
        public JsonResult CreateOrEditTeacherSubject(TeacherSubject input, bool isEdit)
        {
            if (CookiesManage.GetUser().RoleId != RoleKey.Admin)
            {
                return(Json(new { status = false, mess = "Bạn không có quyền" }));
            }
            try
            {
                if (input.FinishTime.HasValue && input.StartTime > input.FinishTime)
                {
                    return(Json(new { status = false, mess = "Thời gian không hợp lệ" }));
                }
                if (isEdit) //update
                {
                    using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
                    {
                        var elm = unitofwork.TeacherSubjects.Get(input.Id);
                        if (elm != null) //update
                        {
                            elm = input;
                            unitofwork.TeacherSubjects.Put(elm, elm.Id);
                            unitofwork.Complete();
                            return(Json(new { status = true, mess = "Cập nhập thành công" }));
                        }
                        else
                        {
                            return(Json(new { status = false, mess = "Không tồn tại" }));
                        }
                    }
                }
                else
                {
                    using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
                    {
                        unitofwork.TeacherSubjects.Add(input);

                        unitofwork.Complete();
                        return(Json(new { status = true, mess = "Thêm thành công " }));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new { status = false, mess = "Có lỗi xảy ra: " + ex.Message }));
            }
        }
예제 #12
0
        public ActionResult Detail(int?id, int?page)
        {
            if (!id.HasValue)
            {
                return(Redirect("/Home/e404"));
            }
            using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
            {
                var item = unitofwork.Courses.FirstOrDefault(x => x.Id == id && x.Status);

                if (item == null)
                {
                    return(Redirect("/Home/e404"));
                }
                ViewBag.Rate = unitofwork.Rating.CalculatorRate(item.Id);

                double rateByUser = 0;
                if (CookiesManage.Logined())
                {
                    var user   = CookiesManage.GetUser();
                    var rating = unitofwork.Rating.FirstOrDefault(x => x.CourseId == item.Id && x.Username == user.Username);
                    if (rating != null)
                    {
                        rateByUser = rating.Point;
                    }
                }

                NumberFormatInfo nfi = new NumberFormatInfo
                {
                    NumberDecimalSeparator = "."
                };

                ViewBag.RateByUser = rateByUser.ToString(nfi);

                var subjects = unitofwork.Subjects.Query(x => x.CourseId == id).ToList();

                int pageNumber = (page ?? 1);
                int pageSize   = 6;

                ViewBag.Item = item;

                return(View(subjects.ToPagedList(pageNumber, pageSize)));
            }
        }
예제 #13
0
        public ResponseResult <bool> Login(User user)
        //public ResponseResult<string> Login(UserLoginModel user, string returnUrl)
        {
            var result = ResponseResult <bool> .MakeFailResult();

            if (string.IsNullOrEmpty(user.LoginName) || string.IsNullOrEmpty(user.Password))
            {
                result.Message = CommonMsg.Error_EmptyLoginInfo;
                result.Data    = false;
                return(result);
            }

            if (!user.LoginName.Equals("wangyeping") || !user.Password.Equals("123456"))
            {
                result.Message = CommonMsg.Error_LoginFail;
                result.Data    = false;
                return(result);
            }
            else
            {
                result.Message = CommonMsg.Info_LoginSuccess;
                result.Data    = true;
                result.Success();
            }

            // 登陆成功后设置IsAdmin值,Password置空,再放到cookie中
            //user.IsAdmin = resultFromWcf.Data.IsAdmin;
            user.Password = "";

            FormsAuthentication.SetAuthCookie(user.LoginName, true);
            var cookiesName = string.Format("{0}-{1}", "EnglishLearning.WebApp.Controllers.Api", user.LoginName);

            CookiesManage.SetCookie(cookiesName, user.ToJson(), 10);

            //if (!string.IsNullOrEmpty(returnUrl))
            //{
            //    //return Redirect(returnUrl);
            //    return result;
            //}

            //return RedirectToAction("Index", "Home", new { area = "" });
            return(result);
        }
        public JsonResult RegSubject(int id)
        {
            using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
            {
                if (CookiesManage.Logined())
                {
                    var subject = unitofwork.Subjects.FirstOrDefault(x => x.Id == id);
                    if (subject != null)
                    {
                        var user           = CookiesManage.GetUser();
                        var studentSubject = unitofwork.StudentSubjects
                                             .FirstOrDefault(x => x.Username.ToLower() == user.Username.ToLower() &&
                                                             x.SubjectId == subject.Id);

                        if (studentSubject != null)
                        {
                            return(Json(new { status = false, mess = "Đã đăng ký" }));
                        }
                        else
                        {
                            StudentSubject std = new StudentSubject
                            {
                                SubjectId   = subject.Id,
                                Username    = user.Username,
                                Status      = StatusRegSubject.Pending,
                                CreatedDate = DateTime.Now
                            };
                            try
                            {
                                unitofwork.StudentSubjects.Add(std);
                                unitofwork.Complete();
                                return(Json(new { status = true, mess = "Đăng ký thành công" }));
                            }
                            catch (Exception)
                            {
                                return(Json(new { status = false, mess = "Đăng ký không thành công" }));
                            }
                        }
                    }
                }
                return(Json(new { status = false, mess = "Bạn chưa đăng nhập" }));
            }
        }
        public ActionResult Detail(int?id)
        {
            using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
            {
                var item = unitofwork.Subjects.FirstOrDefault(x => x.Id == id && x.Status);

                if (item == null)
                {
                    return(Redirect("/Home/E404"));
                }
                List <Lecture> lst = new List <Lecture>();
                if (CookiesManage.Logined())
                {
                    var user           = CookiesManage.GetUser();
                    var studentSubject = unitofwork.StudentSubjects
                                         .FirstOrDefault(x => x.Username.ToLower() == user.Username.ToLower() &&
                                                         x.SubjectId == item.Id);

                    if (studentSubject != null)
                    {
                        lst            = unitofwork.Lectures.Query(x => x.SubjectId == item.Id).ToList();
                        ViewBag.IsReg  = true;
                        ViewBag.Status = studentSubject.Status;
                        ViewBag.IsReg  = true;
                        //document
                        var documents = unitofwork.Documents.Query(x => x.SubjectId == item.Id).ToList();
                        ViewBag.Documents = documents;
                    }
                    else
                    {
                        ViewBag.IsReg = false;
                    }
                }

                ViewBag.Item = item;

                string CurrentURL = System.Web.HttpContext.Current.Request.Url.PathAndQuery;
                ViewBag.CurrentURL = CurrentURL;

                return(View(lst));
            }
        }
        public JsonResult DelComment(int commentId)
        {
            if (commentId >= 1)
            {
                using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
                {
                    if (CookiesManage.Logined())
                    {
                        var user    = CookiesManage.GetUser();
                        var comment = unitofwork.Comments.FirstOrDefault(x => x.Id == commentId && x.Username == user.Username);
                        if (comment != null)
                        {
                            var replies = unitofwork.Comments.Query(x => x.ReplyId == comment.Id);

                            foreach (var item in replies)
                            {
                                unitofwork.Comments.Remove(item);
                                unitofwork.Complete();
                            }

                            unitofwork.Comments.Remove(comment);
                            unitofwork.Complete();

                            //xóa thành công
                            return(Json(new { status = true, mess = "Xóa comment thành công" }));
                        }
                        else
                        {
                            return(Json(new { status = false, mess = "Comment không tồn tại" }));
                        }
                    }
                    else
                    {
                        return(Json(new { status = false, mess = "Bạn chưa đăng nhập" }));
                    }
                }
            }
            else
            {
                return(Json(new { status = false, mess = "Lỗi dữ liệu" }));
            }
        }
 public ActionResult SubmitTest(int lectureId)
 {
     if (CookiesManage.Logined())
     {
         using (var workScope = new UnitOfWork(new ELearningDBContext()))
         {
             var lecture = workScope.Lectures.FirstOrDefault(x => x.Id == lectureId);
             if (lecture == null || !lecture.IsTest)
             {
                 return(RedirectToAction("Index", "Subject"));
             }
             ViewBag.Lecture = lecture;
             return(View());
         }
     }
     else
     {
         return(Redirect("/account/login?ReturnUrl=" + System.Web.HttpContext.Current.Request.Url.PathAndQuery));
     }
 }
예제 #18
0
        public JsonResult UpdatePass(string OldPassword, string NewPassword, string RePassword)
        {
            if (OldPassword == "" || NewPassword == "" || RePassword == "")
            {
                return(Json(new { status = false, mess = "Không được để trống" }));
            }
            if (!CookiesManage.Logined())
            {
                return(Json(new { status = false, mess = "Chưa đăng nhập" }));
            }
            if (NewPassword != RePassword)
            {
                return(Json(new { status = false, mess = "Mật khẩu không khớp" }));
            }
            var user = CookiesManage.GetUser();

            using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
            {
                var account = unitofwork.Account.FirstOrDefault(x => x.Username.ToLower() == user.Username.ToLower());
                if (account != null)
                {
                    try
                    {
                        string passwordFactory = OldPassword + VariableExtensions.KeyCryptor;
                        string passwordCryptor = CryptorEngine.Encrypt(passwordFactory, true);

                        if (passwordCryptor == account.Password)
                        {
                            passwordFactory = "";
                            passwordCryptor = "";

                            passwordFactory = NewPassword + VariableExtensions.KeyCryptor;
                            passwordCryptor = CryptorEngine.Encrypt(passwordFactory, true);

                            account.Password = passwordCryptor;
                            unitofwork.Account.Put(account, account.Username);
                            unitofwork.Complete();

                            //Đăng xuất
                            var nameCookie = Request.Cookies["name_student"];
                            if (nameCookie != null)
                            {
                                var myCookie = new HttpCookie("name_student")
                                {
                                    Expires = DateTime.Now.AddDays(-1d)
                                };
                                Response.Cookies.Add(myCookie);
                            }

                            //Login luon
                            var cookieClient       = account.Username;
                            var decodeCookieClient = CryptorEngine.Encrypt(cookieClient, true);

                            var userCookie = new HttpCookie("name_student")
                            {
                                Value   = decodeCookieClient,
                                Expires = DateTime.Now.AddDays(30)
                            };
                            HttpContext.Response.Cookies.Add(userCookie);

                            return(Json(new { status = true, mess = "Cập nhật thành công" }));
                        }
                        else
                        {
                            return(Json(new { status = false, mess = "mật khẩu cũ không đúng" }));
                        }
                    }
                    catch (Exception ex)
                    {
                        return(Json(new { status = false, mess = "Cập nhật không thành công", ex }));
                    }
                }
                else
                {
                    return(Json(new { status = false, mess = "Tài khoản không khả dụng" }));
                }
            }
        }
예제 #19
0
 public static BELibrary.Entity.Account GetCurrentUser()
 {
     return(CookiesManage.GetUser());
 }
예제 #20
0
        public JsonResult CreateOrEdit(Account input, bool isEdit, string oldPassword, string rePassword)
        {
            try
            {
                if (isEdit) //update
                {
                    using (var workScope = new UnitOfWork(new PatientManagementDbContext()))
                    {
                        var elm = workScope.Accounts.Get(input.Id);

                        if (elm != null) //update
                        {
                            //xu ly password
                            if (!string.IsNullOrEmpty(input.Password) || oldPassword != "")
                            {
                                if (oldPassword == "" || input.Password == "" || rePassword == "")
                                {
                                    return(Json(new { status = false, mess = "Không được để trống" }));
                                }
                                if (!CookiesManage.Logined())
                                {
                                    return(Json(new { status = false, mess = "Chưa đăng nhập" }));
                                }
                                if (input.Password != rePassword)
                                {
                                    return(Json(new { status = false, mess = "Mật khẩu không khớp" }));
                                }

                                var passwordFactory = input.Password + VariableExtensions.KeyCrypto;
                                var passwordCryptor = CryptorEngine.Encrypt(passwordFactory, true);
                                input.Password = passwordCryptor;
                            }
                            else
                            {
                                input.Password = elm.Password;
                            }

                            input.UserName = elm.UserName;

                            if (input.Role == RoleKey.Admin)
                            {
                                input.PatientId = null;
                                input.DoctorId  = null;
                            }
                            else if (input.Role == RoleKey.Doctor)
                            {
                                input.PatientId = null;
                            }
                            else if (input.Role == RoleKey.Patient)
                            {
                                input.DoctorId = null;
                            }
                            elm = input;

                            workScope.Accounts.Put(elm, elm.Id);
                            workScope.Complete();

                            if (input.UserName != GetCurrentUser().UserName)
                            {
                                return(Json(new { status = true, mess = "Cập nhập thành công " }));
                            }
                            //Đăng xuất
                            var nameCookie = Request.Cookies[CookiesKey.Client];
                            if (nameCookie != null)
                            {
                                var myCookie = new HttpCookie(CookiesKey.Client)
                                {
                                    Expires = DateTime.Now.AddDays(-1d)
                                };
                                Response.Cookies.Add(myCookie);
                            }

                            //Login luon
                            if (HttpContext.Request.Url != null)
                            {
                                var host = HttpContext.Request.Url.Authority;

                                var cookieClient       = elm.UserName + "|" + host.ToLower() + "|" + elm.Id;
                                var decodeCookieClient = CryptorEngine.Encrypt(cookieClient, true);
                                var userCookie         = new HttpCookie(CookiesKey.Client)
                                {
                                    Value   = decodeCookieClient,
                                    Expires = DateTime.Now.AddDays(30)
                                };
                                HttpContext.Response.Cookies.Add(userCookie);
                            }
                            else
                            {
                                return(Json(new { status = false, mess = "Lỗi" }));
                            }
                            return(Json(new { status = true, mess = "Cập nhập thành công " }));
                        }
                        else
                        {
                            return(Json(new { status = false, mess = "Không tồn tại " + KeyElement }));
                        }
                    }
                }
                else //Thêm mới
                {
                    using (var workScope = new UnitOfWork(new PatientManagementDbContext()))
                    {
                        if (input.Password != rePassword)
                        {
                            return(Json(new { status = false, mess = "Mật khẩu không khớp" }));
                        }

                        var elm = workScope.Accounts.Query(x => x.UserName.ToLower() == input.UserName.ToLower()).Any();
                        if (elm)
                        {
                            return(Json(new { status = false, mess = "Tên đăng nhập đã tồn tại" }));
                        }

                        var passwordFactory = input.Password + VariableExtensions.KeyCrypto;
                        var passwordCrypto  = CryptorEngine.Encrypt(passwordFactory, true);

                        input.Password = passwordCrypto;
                        input.Id       = Guid.NewGuid();

                        if (input.Role == RoleKey.Admin)
                        {
                            input.PatientId = null;
                            input.DoctorId  = null;
                        }
                        else if (input.Role == RoleKey.Doctor)
                        {
                            input.PatientId = null;
                        }
                        else if (input.Role == RoleKey.Patient)
                        {
                            input.DoctorId = null;
                        }
                        workScope.Accounts.Add(input);
                        workScope.Complete();
                    }
                    return(Json(new { status = true, mess = "Thêm thành công " + KeyElement }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    status = false,
                    mess = "Có lỗi xảy ra: " + ex.Message
                }));
            }
        }
예제 #21
0
        public JsonResult UpdatePass(string oldPassword, string newPassword, string rePassword)
        {
            if (oldPassword == "" || newPassword == "" || rePassword == "")
            {
                return(Json(new { status = false, mess = "Không được để trống" }));
            }
            if (!CookiesManage.Logined())
            {
                return(Json(new { status = false, mess = "Chưa đăng nhập" }));
            }
            if (newPassword != rePassword)
            {
                return(Json(new { status = false, mess = "Mật khẩu không khớp" }));
            }
            var user = CookiesManage.GetUser();

            using (var workScope = new UnitOfWork(new PatientManagementDbContext()))
            {
                var account = workScope.Accounts.FirstOrDefault(x => x.UserName.ToLower() == user.UserName.ToLower());
                if (account != null)
                {
                    try
                    {
                        var passwordFactory = oldPassword + VariableExtensions.KeyCryptorClient;
                        var passwordCryptor = CryptorEngine.Encrypt(passwordFactory, true);

                        if (passwordCryptor == account.Password)
                        {
                            passwordFactory = newPassword + VariableExtensions.KeyCryptorClient;
                            passwordCryptor = CryptorEngine.Encrypt(passwordFactory, true);

                            account.Password = passwordCryptor;
                            workScope.Accounts.Put(account, account.Id);
                            workScope.Complete();

                            //Đăng xuất
                            var nameCookie = Request.Cookies[CookiesKey.Client];
                            if (nameCookie != null)
                            {
                                var myCookie = new HttpCookie(CookiesKey.Client)
                                {
                                    Expires = DateTime.Now.AddDays(-1d)
                                };
                                Response.Cookies.Add(myCookie);
                            }

                            //Login luon
                            if (HttpContext.Request.Url != null)
                            {
                                var host = HttpContext.Request.Url.Authority;

                                var cookieClient       = account.UserName + "|" + host.ToLower() + "|" + account.Id;
                                var decodeCookieClient = CryptorEngine.Encrypt(cookieClient, true);
                                var userCookie         = new HttpCookie(CookiesKey.Client)
                                {
                                    Value   = decodeCookieClient,
                                    Expires = DateTime.Now.AddDays(30)
                                };
                                HttpContext.Response.Cookies.Add(userCookie);
                                return(Json(new { status = true, mess = "Cập nhật thành công" }));
                            }
                            else
                            {
                                return(Json(new { status = false, mess = "Cập nhật K thành công" }));
                            }
                        }
                        else
                        {
                            return(Json(new { status = false, mess = "mật khẩu cũ không đúng" }));
                        }
                    }
                    catch (Exception ex)
                    {
                        return(Json(new { status = false, mess = "Cập nhật không thành công", ex }));
                    }
                }
                else
                {
                    return(Json(new { status = false, mess = "Tài khoản không khả dụng" }));
                }
            }
        }
        public JsonResult Comment(int commentId, int lectureId, string content, bool?isEdit)
        {
            if (content.Length > 0 && lectureId >= 1)
            {
                using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
                {
                    if (CookiesManage.Logined())
                    {
                        var lecture = unitofwork.Lectures.FirstOrDefault(x => x.Id == lectureId);
                        var user    = CookiesManage.GetUser();
                        if (lecture != null)
                        {
                            if (isEdit.HasValue && isEdit.GetValueOrDefault())
                            {
                                var comment = unitofwork.Comments.FirstOrDefault(x => x.Id == commentId && x.Username == user.Username);

                                if (comment != null)
                                {
                                    comment.Content = content;
                                    comment.Time    = DateTime.Now;
                                    unitofwork.Comments.Put(comment, comment.Id);
                                    unitofwork.Complete();

                                    var obj = new
                                    {
                                        comment.Id,
                                        Time = comment.Time.ToString("dd/MM/yyyy HH:mm"),
                                        user.Username,
                                        Content = content
                                    };

                                    //Sửa thành công
                                    return(Json(new { status = true, mess = "", obj }));
                                }
                                else
                                {
                                    return(Json(new { status = false, mess = "Comment không tồn tại" }));
                                }
                            }
                            if (commentId == -1)
                            {
                                var comment = new Comment
                                {
                                    LectureId = lecture.Id,
                                    Status    = true,
                                    Time      = DateTime.Now,
                                    Username  = user.Username,
                                    Content   = content
                                };
                                unitofwork.Comments.Add(comment);
                                unitofwork.Complete();

                                //Thêm mới comment
                                var obj = new
                                {
                                    comment.Id,
                                    Time = comment.Time.ToString("dd/MM/yyyy HH:mm"),
                                    user.Username,
                                    Content = content
                                };
                                return(Json(new { status = true, mess = "", obj }));
                            }
                            else
                            {
                                var comment = unitofwork.Comments.FirstOrDefault(x => x.Id == commentId);

                                if (comment != null)
                                {
                                    var reply = new Comment
                                    {
                                        LectureId = lecture.Id,
                                        Status    = true,
                                        Time      = DateTime.Now,
                                        Username  = user.Username,
                                        ReplyId   = comment.Id,
                                        Content   = content
                                    };

                                    unitofwork.Comments.Add(reply);
                                    unitofwork.Complete();

                                    var obj = new
                                    {
                                        reply.Id,
                                        Time = reply.Time.ToString("dd/MM/yyyy HH:mm"),
                                        user.Username,
                                        Content = content
                                    };

                                    //Thêm mới reply
                                    return(Json(new { status = true, mess = "", obj }));
                                }
                                else
                                {
                                    return(Json(new { status = false, mess = "Comment không tồn tại" }));
                                }
                            }
                        }
                        else
                        {
                            return(Json(new { status = false, mess = "Bài học không tồn tại" }));
                        }
                    }
                    else
                    {
                        return(Json(new { status = false, mess = "Bạn chưa đăng nhập" }));
                    }
                }
            }
            else
            {
                return(Json(new { status = false, mess = "Lỗi dữ liệu" }));
            }
        }
        public JsonResult SendTest(int lectureId, HttpPostedFileBase testFile)
        {
            if (!CookiesManage.Logined())
            {
                return(Json(new { status = false, mess = "Chưa đăng nhập" }));
            }
            var user = CookiesManage.GetUser();

            using (var workScope = new UnitOfWork(new ELearningDBContext()))
            {
                var lecture = workScope.Lectures.FirstOrDefault(x => x.Id == lectureId);
                if (lecture == null || !lecture.IsTest)
                {
                    return(Json(new { status = false, mess = "Lỗi: Không gửi được bài học này!" }));
                }

                var studentTest = new StudentTest
                {
                    Username = user.Username
                };
                try
                {
                    if (testFile?.FileName != null)
                    {
                        if (testFile.ContentLength >= FileKey.MaxTestLength)
                        {
                            return(Json(new { status = false, mess = L.T("FileMaxLength") }));
                        }
                        var splitFilename = testFile.FileName.Split('.');
                        if (splitFilename.Length > 1)
                        {
                            var fileExt = splitFilename[splitFilename.Length - 1];

                            // //Check ext

                            if (FileKey.FileTestExtensionApprove().Any(x => x == fileExt))
                            {
                                var slugName = StringHelper.ConvertToAlias(user.FullName);
                                var fileName = slugName + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + fileExt;
                                var path     = Path.Combine(Server.MapPath("~/FileUploads/files/test/"), fileName);
                                testFile.SaveAs(path);
                                studentTest.FileAnswer = "/FileUploads/files/test/" + fileName;
                            }
                            else
                            {
                                return(Json(new { status = false, mess = "Lỗi: không hỗ trợ định dạng này!" }));
                            }
                        }
                        else
                        {
                            return(Json(new { status = false, mess = "Lỗi: không có nội dung" }));
                        }
                    }

                    studentTest.LectureId = lecture.Id;
                    studentTest.Status    = false;
                    studentTest.Email     = user.Email;

                    workScope.StudentTests.Add(studentTest);
                    workScope.Complete();
                    return(Json(new { status = true, mess = "Gửi tài thành công" }));
                }
                catch (Exception ex)
                {
                    return(Json(new { status = false, mess = "Lỗi hệ thống!" }));
                }
            }
        }
예제 #24
0
        public JsonResult Update(User us, HttpPostedFileBase avatarUpload)
        {
            if (!CookiesManage.Logined())
            {
                return(Json(new { status = false, mess = "Chưa đăng nhập" }));
            }
            var user = CookiesManage.GetUser();

            using (var unitofwork = new UnitOfWork(new ELearningDBContext()))
            {
                var account = unitofwork.Account.FirstOrDefault(x => x.Username.ToLower() == user.Username.ToLower());
                if (account != null)
                {
                    try
                    {
                        if (avatarUpload != null && avatarUpload.FileName != null)
                        {
                            if (avatarUpload.ContentLength >= FileKey.MaxLength)
                            {
                                return(Json(new { status = false, mess = L.T("FileMaxLength") }));
                            }
                            var splitFilename = avatarUpload.FileName.Split('.');
                            if (splitFilename.Length > 1)
                            {
                                var fileExt = splitFilename[splitFilename.Length - 1];

                                //Check ext

                                if (FileKey.FileExtensionApprove().Any(x => x == fileExt))
                                {
                                    string slugName = StringHelper.ConvertToAlias(account.FullName);
                                    string fileName = slugName + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + fileExt;
                                    var    path     = Path.Combine(Server.MapPath("~/FileUploads/images/avatas/"), fileName);
                                    avatarUpload.SaveAs(path);
                                    us.LinkAvata = "/FileUploads/images/avatas/" + fileName;
                                }
                                else
                                {
                                    return(Json(new { status = false, mess = L.T("FileExtensionReject") }));
                                }
                            }
                            else
                            {
                                return(Json(new { status = false, mess = L.T("FileExtensionReject") }));
                            }
                        }

                        us.RoleId   = RoleKey.Student;
                        us.Status   = true;
                        us.Password = account.Password;
                        us.Username = account.Username;
                        if (string.IsNullOrEmpty(us.LinkAvata))
                        {
                            us.LinkAvata = us.Gender == GenderKey.Male ? "/Content/images/team/2.png" : "/Content/images/team/3.png";
                        }
                        unitofwork.Account.Put(us, us.Username);
                        unitofwork.Complete();

                        //Đăng xuất
                        var nameCookie = Request.Cookies["name_student"];
                        if (nameCookie != null)
                        {
                            var myCookie = new HttpCookie("name_student")
                            {
                                Expires = DateTime.Now.AddDays(-1d)
                            };
                            Response.Cookies.Add(myCookie);
                        }

                        //Login luon
                        var cookieClient       = us.Username;
                        var decodeCookieClient = CryptorEngine.Encrypt(cookieClient, true);

                        var userCookie = new HttpCookie("name_student")
                        {
                            Value   = decodeCookieClient,
                            Expires = DateTime.Now.AddDays(30)
                        };
                        HttpContext.Response.Cookies.Add(userCookie);

                        return(Json(new { status = true, mess = "Cập nhật thành công" }));
                    }
                    catch (Exception ex)
                    {
                        return(Json(new { status = false, mess = "Cập nhật không thành công", ex }));
                    }
                }
                else
                {
                    return(Json(new { status = false, mess = "Tài khoản không khả dụng" }));
                }
            }
        }
예제 #25
0
 public static User GetCurrentUser()
 {
     return(CookiesManage.GetUser());
 }
예제 #26
0
        public JsonResult Update(Account us, HttpPostedFileBase avataUpload)
        {
            if (!CookiesManage.Logined())
            {
                return(Json(new { status = false, mess = "Chưa đăng nhập" }));
            }
            var user = CookiesManage.GetUser();

            using (var workScope = new UnitOfWork(new PatientManagementDbContext()))
            {
                var account = workScope.Accounts.FirstOrDefault(x => x.UserName.ToLower() == user.UserName.ToLower());
                if (account != null)
                {
                    try
                    {
                        if (avataUpload?.FileName != null)
                        {
                            if (avataUpload.ContentLength >= FileKey.MaxLength)
                            {
                                return(Json(new { status = false, mess = L.T("FileMaxLength") }));
                            }
                            var splitFilename = avataUpload.FileName.Split('.');
                            if (splitFilename.Length > 1)
                            {
                                var fileExt = splitFilename[splitFilename.Length - 1];

                                //Check ext

                                if (FileKey.FileExtensionApprove().Any(x => x == fileExt))
                                {
                                    var slugName = StringHelper.ConvertToAlias(account.FullName);
                                    var fileName = slugName + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + fileExt;
                                    var path     = Path.Combine(Server.MapPath("~/FileUploads/images/avatas/"), fileName);
                                    avataUpload.SaveAs(path);
                                    us.LinkAvatar = "/FileUploads/images/avatas/" + fileName;
                                }
                                else
                                {
                                    return(Json(new { status = false, mess = L.T("FileExtensionReject") }));
                                }
                            }
                            else
                            {
                                return(Json(new { status = false, mess = L.T("FileExtensionReject") }));
                            }
                        }

                        us.Password = account.Password;
                        us.UserName = account.UserName;
                        us.Role     = RoleKey.Patient;
                        us.Id       = account.Id;

                        if (string.IsNullOrEmpty(us.LinkAvatar))
                        {
                            us.LinkAvatar = us.Gender ? "/Content/images/team/2.png" : "/Content/images/team/3.png";
                        }
                        account = us;
                        workScope.Accounts.Put(account, account.Id);
                        workScope.Complete();

                        //Đăng xuất
                        var nameCookie = Request.Cookies[CookiesKey.Client];
                        if (nameCookie != null)
                        {
                            var myCookie = new HttpCookie(CookiesKey.Client)
                            {
                                Expires = DateTime.Now.AddDays(-1d)
                            };
                            Response.Cookies.Add(myCookie);
                        }

                        //Login luon
                        if (HttpContext.Request.Url != null)
                        {
                            var host = HttpContext.Request.Url.Authority;

                            var cookieClient       = account.UserName + "|" + host.ToLower() + "|" + account.Id;
                            var decodeCookieClient = CryptorEngine.Encrypt(cookieClient, true);
                            var userCookie         = new HttpCookie(CookiesKey.Client)
                            {
                                Value   = decodeCookieClient,
                                Expires = DateTime.Now.AddDays(30)
                            };
                            HttpContext.Response.Cookies.Add(userCookie);
                            //RedirectToAction("Account", "Edit");
                            return(Json(new { status = true, mess = "Cập nhật thành công" }));
                        }
                        else
                        {
                            return(Json(new { status = false, mess = "Cập nhật K thành công" }));
                        }
                    }
                    catch (Exception ex)
                    {
                        return(Json(new { status = false, mess = "Cập nhật không thành công", ex }));
                    }
                }
                else
                {
                    return(Json(new { status = false, mess = "Tài khoản không khả dụng" }));
                }
            }
        }