public ActionResult Forget(ForgetModel model)
        {
            if (ModelState.IsValid)
            {
                var check = CommonEmail.IsValidEmailAddress(model.Email);

                if (!check)
                {
                    alertLogin         = true;
                    ViewBag.alertLogin = alertLogin;
                    Redirect("Login/Forget");
                    ViewBag.Mes = "Email không đúng định dạng!";
                }
                else
                {
                    var dao    = new UserDao();
                    var result = dao.GetUserWithEmail(model.Email);
                    if (result == null)
                    {
                        alertLogin         = true;
                        ViewBag.alertLogin = alertLogin;
                        Redirect("Login/Forget");
                        ViewBag.Mes = "Email không tồn tại trong hệ thống!";
                    }
                    else
                    {
                        var newPassword = CommonString.GenerateNumber();
                        check = CommonEmail.Send(result.Email, "Lấy lại mật khẩu", string.Format("Mật khẩu của tài khoản '{0}' là: {1}", result.UserName, newPassword));
                        if (check)
                        {
                            check = dao.UpdatePassword(result.ID, Encryptor.MD5Hash(newPassword));
                        }

                        if (check)
                        {
                            ViewBag.alertSuss = true;
                            ViewBag.Mes       = "Đã gửi mật khẩu vào Email!";
                        }
                        else
                        {
                            alertLogin         = true;
                            ViewBag.alertLogin = alertLogin;
                            Redirect("Login/Forget");
                            ViewBag.Mes = "Gửi mật khẩu bị lỗi!";
                        }
                    }
                }
            }

            return(View("Forget"));
        }
        public ActionResult Profile(ProfileViewModel model)
        {
            if (model != null)
            {
                var check = CommonEmail.IsValidEmailAddress(model.Email);
                if (check)
                {
                    var user         = db.User.SingleOrDefault(x => x.ID == model.ID);
                    var base64Avatar = model.ImageUrl;
                    var urlFile      = string.IsNullOrEmpty(base64Avatar) || string.IsNullOrEmpty(model.ImageName) ? null : SaveThumb(base64Avatar, model.ImageName);
                    if (urlFile != null)
                    {
                        user.ImageUrl = urlFile;
                    }
                    user.Name         = model.Name.ToString().Trim();
                    user.Email        = model.Email.ToString().Trim();
                    user.Phone        = model.Phone.ToString().Trim();
                    user.ModifiedDate = DateTime.Now;
                    if (user.GroupID.Equals(CommonConstants.MEMBER_GROUP))
                    {
                        var teacher = db.Teacher.SingleOrDefault(x => x.ID == user.TeacherID);
                        if (teacher != null)
                        {
                            teacher.Name_Teacher = model.Name.ToString().Trim();
                            teacher.ModifiedDate = DateTime.Now;
                        }
                    }
                    db.SaveChanges();
                    var userLogin = (UserLogin)Session[Managing_Teacher_Work.Common.CommonConstants.USER_SESSION];
                    userLogin.Name     = user.Name;
                    userLogin.ImageUrl = user.ImageUrl;

                    SetAlert("Cập nhật thông tin thành công! :D", "success");
                }
                else
                {
                    SetAlert("Email không đúng định dạng! :D", "warning");
                }
            }
            return(RedirectToAction("Profile"));
        }
        public object PostSendEmail([FromBody] object param)
        {
            int   report_id       = 0;
            short?interval_minute = 0;

            JObject paramdata = JObject.Parse(param.ToString());

            if (!string.IsNullOrEmpty(paramdata["report_id"].ToString()))
            {
                report_id = Convert.ToInt32(((JValue)paramdata["report_id"]).Value);
            }

            if (!string.IsNullOrEmpty(paramdata["interval"].ToString()))
            {
                interval_minute = Convert.ToInt16(((JValue)paramdata["interval"]).Value);
            }


            report_ref item = db.Reports.Find(report_id);

            if (item == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "Report does not exist"));
            }

            DataSet ds;

            try
            {
                ds = GetReportData(item, interval_minute);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error occured while exeuting report SQL"));
            }

            string[] strCSVOutput;
            try
            {
                CommonFunctions commfun = new CommonFunctions();
                strCSVOutput = commfun.GetCSVOutput(ds);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error occured while generating CSV file"));
            }

            try
            {
                MemoryStream[] ms    = new MemoryStream[ds.Tables.Count];
                CommonEmail    email = new CommonEmail();
                email.ConfigureDefaultSMTPclient();

                Attachment[] attachments = new Attachment[ds.Tables.Count];

                for (int i = 0; i < strCSVOutput.Length; i++)
                {
                    ms[i]          = new MemoryStream(Encoding.UTF8.GetBytes(strCSVOutput[i]));
                    attachments[i] = new Attachment(ms[i], "Report" + i.ToString() + ".csv", "text/csv");
                }

                string        emailSubject = "eTracker Report : " + item.report_nm + " executed on : " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
                StringBuilder sbEmailbody  = new StringBuilder();
                sbEmailbody.AppendLine("This report is generated from eTracker Reporting Tool");
                sbEmailbody.AppendLine("Report Name : " + item.report_nm);
                sbEmailbody.AppendLine("Description : " + item.report_descr);

                if (attachments != null && attachments.Count() > 0)
                {
                    sbEmailbody.AppendLine("Report output is attached (CSV format)");
                }

                email.SendEmail(item.scheduler_email_ids, emailSubject, sbEmailbody.ToString(), attachments);

                ms = null;
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, "Error occured while sending email"));
            }
            return("Successfully email sent");
        }