public ActionResult ListGroup(int id = 0) { using (var db = new Entities()) { var data = db.asp_Group.ToList(); if (id == 0 && data.Count > 0) { id = data[0].id; } ViewBag.Id = id; return View(data); } }
public ActionResult Group(int id = 0) { using (var db = new Entities()) { var model = new CreateGroupModel(); model.roles = db.asp_Role.Select(x => new RoleData { name = x.name, description = x.description }).ToList(); var data = db.asp_Group.FirstOrDefault(x => x.id == id); if (data != null) { model.id = data.id; model.name = data.name; model.description = data.description; foreach (var item in model.roles) { if (data.asp_Role.Any(x => x.name == item.name)) { item.check = true; } } } return PartialView(model); } }
public static int GetGroupOfUser(string currenUser) { try { using (var db = new Entities()) { //get group var userGroup = db.asp_User.FirstOrDefault(x => x.account == currenUser); var firstOrDefault = userGroup?.asp_Group.FirstOrDefault(); if (firstOrDefault != null) { var groupid = firstOrDefault.id; return groupid; } } } catch (Exception) { return 99; } return 99; }
public ActionResult GetCourseOfCl(string id) { using (var db = new Entities()) { var data = db.Courses.Where(x => x.CLID == id).ToList(); var courses = data.Select(course => new Course() { IDCourse = course.IDCourse, Title = course.Title }).ToList(); return Json(courses, JsonRequestBehavior.AllowGet); } }
public ActionResult Account(CreateAccountModel model) { if (ModelState.IsValid) { using (var db = new Entities()) { var data = db.asp_User.FirstOrDefault(x => x.account == model.account); if (data == null) { //check mat khau if (string.IsNullOrEmpty(model.password)) { TempData["mess"] = "Bạn chưa nhập mật khẩu"; return RedirectToAction("ListAccount", new { id = model.account }); } data = new asp_User { account = model.account, userName = model.name, password = CoreFunction.GetMd5Hash(model.password), email = model.email }; foreach (var item in model.groups) { if (item.check && !data.asp_Group.Any(x => x.id == item.id)) { var groupItem = db.asp_Group.FirstOrDefault(x => x.id == item.id); if (groupItem != null) { data.asp_Group.Add(groupItem); } } else if (!item.check && data.asp_Group.Any(x => x.id == item.id)) { var groupItem = db.asp_Group.FirstOrDefault(x => x.id == item.id); if (groupItem != null) { data.asp_Group.Remove(groupItem); } } } db.asp_User.Add(data); db.SaveChanges(); TempData["mess"] = "Đã thêm dữ liệu thành công"; } else if (model.edit) { data.userName = model.name; if (!string.IsNullOrEmpty(model.password)) { data.password = CoreFunction.GetMd5Hash(model.password); } data.email = model.email; foreach (var item in model.groups) { if (item.check && !data.asp_Group.Any(x => x.id == item.id)) { var groupItem = db.asp_Group.FirstOrDefault(x => x.id == item.id); if (groupItem != null) { data.asp_Group.Add(groupItem); } } else if (!item.check && data.asp_Group.Any(x => x.id == item.id)) { var groupItem = db.asp_Group.FirstOrDefault(x => x.id == item.id); if (groupItem != null) { data.asp_Group.Remove(groupItem); } } } db.SaveChanges(); TempData["mess"] = "Đã cập nhật dữ liệu thành công"; } else { TempData["mess"] = "Tài khoản đã tồn tại"; } } } return RedirectToAction("ListAccount", new { id = model.account }); }
public ActionResult DeleteAccount(string id = "0") { using (var db = new Entities()) { var data = db.asp_User.FirstOrDefault(x => x.account == id); if (data != null) { db.asp_User.Remove(data); db.SaveChanges(); TempData["mess"] = "Bạn đã xóa dữ liệu thành công"; } return RedirectToAction("ListAccount"); } }
public ActionResult ListAccount(string id) { using (var db = new Entities()) { var data = db.asp_User.ToList(); if (string.IsNullOrEmpty(id) && data.Count > 0) { id = data[0].account; } ViewBag.Id = id; return View(data); } }
public ActionResult Account(string id) { using (var db = new Entities()) { var model = new CreateAccountModel(); model.groups = db.asp_Group.Select(x => new GroupData { id = x.id, name = x.name, description = x.description }).ToList(); var data = db.asp_User.FirstOrDefault(x => x.account == id); if (data != null) { model.account = data.account; model.name = data.userName; //model.password model.email = data.email; model.edit = true; foreach (var item in model.groups) { if (data.asp_Group.Any(x => x.id == item.id)) { item.check = true; } } } return PartialView(model); } }
public ActionResult DeleteGroup(int id = 0) { using (var db = new Entities()) { var data = db.asp_Group.FirstOrDefault(x => x.id == id); if (data != null) { var check = db.asp_User.FirstOrDefault(x => x.asp_Group.Any(g => g.id == data.id)); if (check == null) { db.asp_Group.Remove(data); db.SaveChanges(); TempData["mess"] = "Bạn đã xóa dữ liệu thành công"; } else { TempData["mess"] = "Nhóm quyền này đã có tài khoản sử dụng nên không thể xóa được"; return RedirectToAction("ListGroup", new { id = id }); } } return RedirectToAction("ListGroup"); } }
public ActionResult Create(Report report) { try { using (var db = new Entities()) { report.Created = DateTime.Now; var emailOfCm = GetEmailLogin(report.CMID); //call sent email //var pathHtml = Server.MapPath("bodyEmail.html"); //var body = System.IO.File.ReadAllText(pathHtml); //body = String.Format(body, "", DateTime.Now.ToString("hh:mm dd-MM-yyyy"), ""); //var data = db.Courses.FirstOrDefault(x => x.IDCourse == courseID); db.Reports.Add(report); db.SaveChanges(); MailSender mailSender = new MailSender(); mailSender.sendMail(emailOfCm, "Check Report", "Report was submit", "gmail"); return Json(new { status = true }, JsonRequestBehavior.AllowGet); } } catch { return Json(new { status = false }, JsonRequestBehavior.AllowGet); } }
public ActionResult Group(CreateGroupModel model) { if (ModelState.IsValid) { using (var db = new Entities()) { var data = db.asp_Group.FirstOrDefault(x => x.id == model.id); if (data == null) { data = new asp_Group { name = model.name, description = model.description, status = 0 }; foreach (var item in model.roles) { if (item.check && !data.asp_Role.Any(x => x.name == item.name)) { var roleItem = db.asp_Role.FirstOrDefault(x => x.name == item.name); if (roleItem != null) { data.asp_Role.Add(roleItem); } } else if (!item.check && data.asp_Role.Any(x => x.name == item.name)) { var roleItem = db.asp_Role.FirstOrDefault(x => x.name == item.name); if (roleItem != null) { data.asp_Role.Remove(roleItem); } } } db.asp_Group.Add(data); db.SaveChanges(); TempData["mess"] = "Đã thêm dữ liệu thành công"; } else { data.name = model.name; data.description = model.description; foreach (var item in model.roles) { if (item.check && !data.asp_Role.Any(x => x.name == item.name)) { var roleItem = db.asp_Role.FirstOrDefault(x => x.name == item.name); if (roleItem != null) { data.asp_Role.Add(roleItem); } } else if (!item.check && data.asp_Role.Any(x => x.name == item.name)) { var roleItem = db.asp_Role.FirstOrDefault(x => x.name == item.name); if (roleItem != null) { data.asp_Role.Remove(roleItem); } } } db.SaveChanges(); TempData["mess"] = "Đã cập nhật dữ liệu thành công"; } } } return RedirectToAction("ListGroup", new { id = model.id }); }
// GET: Admin/Report/Create public ActionResult Create(int courseID) { using (var db = new Entities()) { var data = db.Courses.FirstOrDefault(x => x.IDCourse == courseID); return View(data); } }
public ActionResult Comment(int id, string comment) { try { using (var db = new Entities()) { var update = db.Reports.FirstOrDefault(x => x.ID == id); if (update != null) { update.Comment = comment; db.SaveChanges(); return Json(new { status = true }, JsonRequestBehavior.AllowGet); } } } catch { return Json(new { status = false }, JsonRequestBehavior.AllowGet); } return Json(new { status = false }, JsonRequestBehavior.AllowGet); }
public ActionResult Approve(int id, int status) { try { using (var db = new Entities()) { var update = db.Reports.FirstOrDefault(x => x.ID == id); var emailOfCl = GetEmailLogin(update.CLID); var emailOfCM = GetEmailLogin(update.CMID); var emailOfPVC = GetEmailLogin(update.PVCID); if (update != null) { update.Status = status; db.SaveChanges(); MailSender mailSender = new MailSender(); mailSender.sendMail(emailOfCl, "Check Report", "Report was Approve", "gmail"); mailSender.sendMail(emailOfCM, "Check Report", "Report was Approve", "gmail"); mailSender.sendMail(emailOfPVC, "Check Report", "Report was Approve", "gmail"); return Json(new { status = true }, JsonRequestBehavior.AllowGet); } } } catch (Exception ex) { return Json(new { status = false }, JsonRequestBehavior.AllowGet); } return Json(new { status = false }, JsonRequestBehavior.AllowGet); }
public static int CountReport(int status, DateTime start, DateTime endDate) { using (var db = new Entities()) { return db.Reports.Where(x => x.Status == status && x.Created >= start && x.Created < endDate).Count(); } }
// GET: Admin/Report public ActionResult Index(int id = 0) { string currenUser = User.Identity.Name; using (var db = new Entities()) { //get group var userGroup = db.asp_User.FirstOrDefault(x => x.account == currenUser); if (userGroup != null) { var groupid = userGroup.asp_Group.FirstOrDefault().id; ViewBag.groupid = groupid; if (groupid == 5) { var data = db.Reports.Where(x => x.CLID == currenUser).ToList(); if (id == 0 && data.Count > 0) { ViewBag.Id = data[0].ID; } else { ViewBag.Id = id; } return View(data); } if (groupid == 4) { var data = db.Reports.Where(x => x.CMID == currenUser && x.Status == 1).ToList(); if (id == 0 && data.Count > 0) { ViewBag.Id = data[0].ID; } else { ViewBag.Id = id; } return View(data); } if (groupid == 3) { var data = db.Reports.Where(x => x.DLTID == currenUser && x.Status == 2).ToList(); if (id == 0 && data.Count > 0) { ViewBag.Id = data[0].ID; } else { ViewBag.Id = id; } return View(data); } if (groupid == 2) { var data = db.Reports.Where(x => x.PVCID == currenUser && x.Status == 3).ToList(); if (id == 0 && data.Count > 0) { ViewBag.Id = data[0].ID; } else { ViewBag.Id = id; } return View(data); } if (groupid == 0) { var data = db.Reports.Where(x => x.Status == 3).ToList(); if (id == 0 && data.Count > 0) { ViewBag.Id = data[0].ID; } else { ViewBag.Id = id; } return View(data); } } return View(); } }
public String GetReportJson(int status) { using (var db = new Entities()) { var kq = new List<int>(); //m1 var b1 = new DateTime(DateTime.Now.Year, 1, 1); var e1 = new DateTime(DateTime.Now.Year, 2, 1); kq.Add(CountReport(status, b1, e1)); //m2 var b2 = new DateTime(DateTime.Now.Year, 2, 1); var e2 = new DateTime(DateTime.Now.Year, 3, 1); kq.Add(CountReport(status, b2, e2)); //m3 var b3 = new DateTime(DateTime.Now.Year, 3, 1); var e3 = new DateTime(DateTime.Now.Year, 4, 1); kq.Add(CountReport(status, b3, e3)); var b4 = new DateTime(DateTime.Now.Year, 4, 1); var e4 = new DateTime(DateTime.Now.Year, 5, 1); kq.Add(CountReport(status, b4, e4)); var b5 = new DateTime(DateTime.Now.Year, 5, 1); var e5 = new DateTime(DateTime.Now.Year, 6, 1); kq.Add(CountReport(status, b5, e5)); var b6 = new DateTime(DateTime.Now.Year, 6, 1); var e6 = new DateTime(DateTime.Now.Year, 7, 1); kq.Add(CountReport(status, b6, e6)); var b7 = new DateTime(DateTime.Now.Year, 7, 1); var e7 = new DateTime(DateTime.Now.Year, 8, 1); kq.Add(CountReport(status, b7, e7)); var b8 = new DateTime(DateTime.Now.Year, 8, 1); var e8 = new DateTime(DateTime.Now.Year, 9, 1); kq.Add(CountReport(status, b8, e8)); var b9 = new DateTime(DateTime.Now.Year, 9, 1); var e9 = new DateTime(DateTime.Now.Year, 10, 1); kq.Add(CountReport(status, b9, e9)); var b10 = new DateTime(DateTime.Now.Year, 10, 1); var e10 = new DateTime(DateTime.Now.Year, 11, 1); kq.Add(CountReport(status, b10, e10)); var b11 = new DateTime(DateTime.Now.Year, 11, 1); var e11 = new DateTime(DateTime.Now.Year, 12, 1); kq.Add(CountReport(status, b11, e11)); var b12 = new DateTime(DateTime.Now.Year, 12, 1); var e12 = new DateTime(DateTime.Now.Year, 1, 1).AddYears(1); kq.Add(CountReport(status, b12, e12)); return JsonConvert.SerializeObject(kq); } }
public string GetEmailLogin(string username) { string currenUser = User.Identity.Name; using (var db = new Entities()) { //get group var userGroup = db.asp_User.FirstOrDefault(x => x.userName == username); if (userGroup != null) { return userGroup.email; } } return null; }
// GET: Admin/Report/Details/5 public ActionResult Details(int id) { using (var db = new Entities()) { var data = db.Reports.FirstOrDefault(x => x.ID == id); return PartialView(data); } }