public JsonResult editAttendance(string id, string aDate, string presence) { int x = int.Parse(id); if (Request.IsAjaxRequest()) { FastAndEasyEntities db = new FastAndEasyEntities(); Attendence a = new Attendence(); a = db.Attendences.Find(x); a.Date = DateTime.Parse(aDate); if (presence == "-") { a.Reasonable = "No"; db.Entry(a).Property(at => at.Reasonable).IsModified = true; } a.Present = presence; db.Entry(a).Property(at => at.Date).IsModified = true; db.Entry(a).Property(at => at.Present).IsModified = true; db.SaveChanges(); ModelState.Clear(); return(new JsonResult { Data = " ", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } return(new JsonResult { Data = "error", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public JsonResult studentPay(string sId, string groupId, string amount) { int sid = int.Parse(sId); int grpID = int.Parse(groupId); double sum = float.Parse(amount); using (FastAndEasyEntities db = new FastAndEasyEntities()) { int? levelId = db.Groups.Where(g => g.Id == grpID).FirstOrDefault().Level; double?cost = db.Levels.Where(l => l.Id == levelId).FirstOrDefault().Price; var x = sum / cost; for (int i = 1; i <= x; i++) { Attendence a = new Attendence(); a.Student = sid; db.Attendences.Add(a); db.SaveChanges(); ModelState.Clear(); } return(Json("success", JsonRequestBehavior.AllowGet)); } }
public ActionResult EditPassword(string oldPass, string newPass, string newPassConfirm, Reception d) { FastAndEasyEntities _db = new FastAndEasyEntities(); string receptionistName = HttpContext.User.Identity.Name; string pass = _db.Receptions.Where(p => (p.Email.Equals(receptionistName)) || (p.UserName.Equals(receptionistName))).FirstOrDefault().Password; ViewBag.Pass = pass; if (Crypto.VerifyHashedPassword(pass, oldPass)) { if ((newPass == newPassConfirm)) { db.Receptions.Attach(d); d.Password = Crypto.HashPassword(newPass); db.Entry(d).Property(p => p.Password).IsModified = true; db.SaveChanges(); return(RedirectToAction("Index", new { id = d.Id })); } else { ViewBag.Error = "Passwords Do not Match"; } } else { ViewBag.Error = "Wrong Current Password"; } return(View()); }
// GET: Reception public ActionResult Index(int id) { FastAndEasyEntities db = new FastAndEasyEntities(); int x = db.Receptions.Where(t => t.Id == id).FirstOrDefault().Id; ViewBag.Id = x; return(View(x)); }
public ActionResult EditPassword(int id) { FastAndEasyEntities _db = new FastAndEasyEntities(); string receptionistName = HttpContext.User.Identity.Name; int rId = _db.Receptions.Where(p => (p.Email.Equals(receptionistName)) || (p.UserName.Equals(receptionistName))).FirstOrDefault().Id; if (id == rId) { Reception d = _db.Receptions.Find(id); return(View(d)); } return(View()); }
public JsonResult deleteStudent(string id, string LastName, string FirstName) { int x = int.Parse(id); using (FastAndEasyEntities db = new FastAndEasyEntities()) { Student d = new Student(); d = db.Students.Find(x); db.Entry(d).State = EntityState.Deleted; db.SaveChanges(); ModelState.Clear(); return(Json("", JsonRequestBehavior.AllowGet)); } }
public JsonResult getManager() { if (Request.IsAjaxRequest()) { FastAndEasyEntities db = new FastAndEasyEntities(); var manager = db.Managers.Select(m => new { m.Id, m.UserName, m.Email, m.Phone, m.LastName, m.FirstName, m.ImagePath }).FirstOrDefault(); return(new JsonResult { Data = manager, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } return(new JsonResult { Data = "error", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public JsonResult addNewReceptionist(string LastName, string FirstName, string UserName, string pass, string Phone, string Email) { FastAndEasyEntities db = new FastAndEasyEntities(); Reception manager = new Reception(); manager.UserName = UserName; manager.Password = Crypto.HashPassword(pass); manager.LastName = LastName; manager.FirstName = FirstName; manager.Phone = Phone; manager.Email = Email; manager.RoleId = 3; db.Receptions.Add(manager); db.SaveChanges(); ModelState.Clear(); return(Json("", JsonRequestBehavior.AllowGet)); }
public JsonResult editStudent(string id, string LastName, string FirstName) { int x = int.Parse(id); using (FastAndEasyEntities db = new FastAndEasyEntities()) { Student d = new Student(); d = db.Students.Find(x); db.Students.Attach(d); d.LastName = LastName; d.FirstName = FirstName; db.Entry(d).Property(p => p.LastName).IsModified = true; db.Entry(d).Property(p => p.FirstName).IsModified = true; db.SaveChanges(); ModelState.Clear(); return(Json("", JsonRequestBehavior.AllowGet)); } }
public JsonResult addStudent(string id, string LastName, string FirstName) { int x = int.Parse(id); using (FastAndEasyEntities db = new FastAndEasyEntities()) { Student d = new Student(); d.UserName = LastName + FirstName; d.Password = Crypto.HashPassword("1111"); d.LastName = LastName; d.FirstName = FirstName; d.RoleId = 5; d.Group = x; db.Students.Add(d); db.SaveChanges(); ModelState.Clear(); return(Json(d, JsonRequestBehavior.AllowGet)); } }
public JsonResult updateTeacher(string id, string LastName, string FirstName, string UserName, string pass, string Phone, string Email) { int Id = int.Parse(id); FastAndEasyEntities db = new FastAndEasyEntities(); Teacher manager = new Teacher(); manager = db.Teachers.Find(Id); manager.UserName = UserName; manager.Password = Crypto.HashPassword(pass); manager.LastName = LastName; manager.FirstName = FirstName; manager.Phone = Phone; manager.Email = Email; manager.RoleId = 4; db.Entry(manager).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); ModelState.Clear(); return(Json("", JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(HttpPostedFileBase ImageFile, Reception d, string pass, string passConf) { if (ModelState.IsValid) { if (pass == passConf) { var db = new FastAndEasyEntities(); db.Receptions.Attach(d); if (ImageFile != null) { string fileName = Path.GetFileNameWithoutExtension(ImageFile.FileName); string fileExtension = Path.GetExtension(ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + fileExtension; d.ImagePath = "/img/photos/reception/" + fileName; fileName = Path.Combine(Server.MapPath("/img/photos/reception/"), fileName); ImageFile.SaveAs(fileName); } db.Entry(d).Property(p => p.LastName).IsModified = true; db.Entry(d).Property(p => p.FirstName).IsModified = true; db.Entry(d).Property(p => p.DoB).IsModified = true; db.Entry(d).Property(p => p.Address).IsModified = true; db.Entry(d).Property(p => p.Phone).IsModified = true; db.Entry(d).Property(p => p.Email).IsModified = true; db.Entry(d).Property(p => p.ImagePath).IsModified = true; db.SaveChanges(); return(RedirectToAction("Index", new { id = d.Id })); } else { ViewBag.Pass = "******"; return(View()); } } return(View()); }
public override bool ValidateUser(string username, string password) { bool isValid = false; using (FastAndEasyEntities _db = new FastAndEasyEntities()) { try { Admin admin = (from a in _db.Admins where a.Email == username || a.UserName == username select a).FirstOrDefault(); SettingsContext context = new SettingsContext(); string adminName = (string)context["UserName"]; int aID = _db.Admins.Where(a => a.Email.Equals(adminName) || a.UserName.Equals(adminName)).FirstOrDefault().Id; if (admin != null && Crypto.VerifyHashedPassword(admin.Password, password)) { isValid = true; } Manager manager = (from m in _db.Managers where m.Email == username || m.UserName == username select m).FirstOrDefault(); if (manager != null && Crypto.VerifyHashedPassword(manager.Password, password)) { isValid = true; } Reception receptionist = (from r in _db.Receptions where r.Email == username || r.UserName == username select r).FirstOrDefault(); if (receptionist != null && Crypto.VerifyHashedPassword(receptionist.Password, password)) { isValid = true; } Teacher teacher = (from t in _db.Teachers where t.Email == username || t.UserName == username select t).FirstOrDefault(); if (teacher != null && Crypto.VerifyHashedPassword(teacher.Password, password)) { isValid = true; } Student student = (from s in _db.Students where s.UserName == username || s.Email == username select s).FirstOrDefault(); string pupName = (string)context["UserName"]; int pID = _db.Students.Where(p => p.UserName.Equals(pupName)).FirstOrDefault().Id; if (student != null && Crypto.VerifyHashedPassword(student.Password, password)) { isValid = true; } } catch { isValid = false; } } return(isValid); }
public override string[] GetRolesForUser(string email) { string[] role = new string[] { }; using (FastAndEasyEntities _db = new FastAndEasyEntities()) { try { // Получаем пользователя Admin admin = (from a in _db.Admins where a.Email == email || a.UserName == email select a).FirstOrDefault(); if (admin != null) { // получаем роль Role adminRole = _db.Roles.Find(admin.RoleId); if (adminRole != null) { role = new string[] { adminRole.Role1 }; } } } catch { role = new string[] { }; } } using (FastAndEasyEntities _db = new FastAndEasyEntities()) { try { // Получаем пользователя Manager director = (from d in _db.Managers where d.Email == email || d.UserName == email select d).FirstOrDefault(); if (director != null) { // получаем роль Role directorRole = _db.Roles.Find(director.RoleId); if (directorRole != null) { role = new string[] { directorRole.Role1 }; } } } catch { role = new string[] { }; } } using (FastAndEasyEntities _db = new FastAndEasyEntities()) { try { // Получаем пользователя Teacher teacher = (from t in _db.Teachers where t.Email == email || t.UserName == email select t).FirstOrDefault(); if (teacher != null) { // получаем роль Role teacherRole = _db.Roles.Find(teacher.RoleId); if (teacherRole != null) { role = new string[] { teacherRole.Role1 }; } } } catch { role = new string[] { }; } } using (FastAndEasyEntities _db = new FastAndEasyEntities()) { try { // Получаем пользователя Reception parent = (from p in _db.Receptions where p.Email == email || p.UserName == email select p).FirstOrDefault(); if (parent != null) { // получаем роль Role parentRole = _db.Roles.Find(parent.RoleId); if (parentRole != null) { role = new string[] { parentRole.Role1 }; } } } catch { role = new string[] { }; } } using (FastAndEasyEntities _db = new FastAndEasyEntities()) { try { // Получаем пользователя Student pupil = (from p in _db.Students where p.UserName == email || p.Email == email select p).FirstOrDefault(); if (pupil != null) { // получаем роль Role pupRole = _db.Roles.Find(pupil.RoleId); if (pupRole != null) { role = new string[] { pupRole.Role1 }; } } } catch { role = new string[] { }; } } return(role); }
public override bool IsUserInRole(string username, string roleName) { bool outputResult = false; //Находим пользователя using (FastAndEasyEntities _db = new FastAndEasyEntities()) { try { // Получаем пользователя Admin admin = (from a in _db.Admins where a.Email == username || a.UserName == username select a).FirstOrDefault(); Manager director = (from d in _db.Managers where d.Email == username || d.UserName == username select d).FirstOrDefault(); Teacher teacher = (from t in _db.Teachers where t.Email == username || t.UserName == username select t).FirstOrDefault(); Reception parent = (from p in _db.Receptions where p.Email == username || p.UserName == username select p).FirstOrDefault(); Student pup = (from p in _db.Students where p.UserName == username || p.Email == username select p).FirstOrDefault(); if (admin != null) { // получаем роль Role adminRole = _db.Roles.Find(admin.RoleId); //сравниваем if (adminRole != null && adminRole.Role1 == roleName) { outputResult = true; } } if (director != null) { // получаем роль Role directorRole = _db.Roles.Find(director.RoleId); //сравниваем if (directorRole != null && directorRole.Role1 == roleName) { outputResult = true; } } if (teacher != null) { // получаем роль Role teacherRole = _db.Roles.Find(teacher.RoleId); //сравниваем if (teacherRole != null && teacherRole.Role1 == roleName) { outputResult = true; } } if (parent != null) { // получаем роль Role parentRole = _db.Roles.Find(parent.RoleId); //сравниваем if (parentRole != null && parentRole.Role1 == roleName) { outputResult = true; } } if (pup != null) { // получаем роль Role pupRole = _db.Roles.Find(pup.RoleId); //сравниваем if (pupRole != null && pupRole.Role1 == roleName) { outputResult = true; } } } catch { outputResult = false; } } return(outputResult); }
public JsonResult editManager(string LastName, string FirstName, string UserName, string pass, string Phone, string Email) { string UserNameError = " "; string LNameError = " "; string FNameError = " "; string PassError = " "; string PhoneError = " "; string EmailError = " "; var rName = new Regex(@"^[A-Z][a-z]+$"); var hasNumber = new Regex(@"[0-9]+"); var hasChar = new Regex(@"[A-Za-z]+"); var hasMiniMaxChars = new Regex(@".{6, }"); var rLogin = new Regex(@"^[A-Za-z\d]+$"); var rPhone = new Regex(@"^\+9989[0-9]{8}$"); var rEmail = new Regex(@"^.+$"); FastAndEasyEntities db = new FastAndEasyEntities(); if (!rName.IsMatch(LastName)) { LNameError = "Lastname should only contain letters with a capital letter at the beginning and not be empty! Example: 'Khamzaev'!"; } if (!rName.IsMatch(FirstName)) { FNameError = "Firstname should only contain letters with a capital letter at the beginning and not be empty! Example: 'Asilbek'!"; } if (!rLogin.IsMatch(UserName)) { UserNameError = "Username should only contain letters and numbers and not be empty! Example: 'AceTheKing', 'ACETHEKING', 'acetheking' or 'acetheking7776'!"; } //if (ifAExists(UserName) != null) //{ // UserNameError = "The user already exists!"; //} if (ifMExists(UserName) != null) { UserNameError = "The user already exists!"; } if (ifRExists(UserName) != null) { UserNameError = "The user already exists!"; } if (ifTExists(UserName) != null) { UserNameError = "The user already exists!"; } if (ifSExists(UserName) != null) { UserNameError = "The user already exists!"; } if (!hasNumber.IsMatch(pass)) { PassError = "The password should contain at least one number!"; } else if (!hasChar.IsMatch(pass)) { PassError = "The password should contain at least one letter!"; } else if (!hasMiniMaxChars.IsMatch(pass)) { PassError = "The password should be at least six characters long!"; } else { PassError = " "; } if (!rPhone.IsMatch(Phone)) { PhoneError = "Enter full UZB phone number! Example: '+998945677776'"; } if (!string.IsNullOrEmpty(Email) && !string.IsNullOrWhiteSpace(Email)) { if (!IsValidEmail(Email)) { EmailError = "Invalid email address!"; } } if (UserNameError == " " && PassError == " " && LNameError == " " && FNameError == " " && PhoneError == " " && EmailError == " ") { Manager manager = new Manager(); manager = db.Managers.Find(1); manager.UserName = UserName; manager.Password = Crypto.HashPassword(pass); manager.LastName = LastName; manager.FirstName = FirstName; manager.Phone = Phone; manager.Email = Email; manager.RoleId = 2; db.Entry(manager).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); ModelState.Clear(); var result = "success"; return(Json(result, JsonRequestBehavior.AllowGet)); } else { var result = new { LNameError, FNameError, UserNameError, PassError, PhoneError, EmailError }; return(Json(result, JsonRequestBehavior.AllowGet)); } }
public MembershipUser CreateUser(string email, string password) { MembershipUser membershipUser = GetUser(email, false); if (membershipUser == null) { try { using (FastAndEasyEntities _db = new FastAndEasyEntities()) { Admin admin = new Admin(); admin.Email = email; admin.Password = Crypto.HashPassword(password); //admin.CreationDate = DateTime.Now; if (_db.Roles.Find(1) != null) { admin.RoleId = 1; } _db.Admins.Add(admin); _db.SaveChanges(); membershipUser = GetUser(email, false); return(membershipUser); #pragma warning disable CS0162 // Unreachable code detected Manager director = new Manager(); #pragma warning restore CS0162 // Unreachable code detected director.Email = email; director.Password = Crypto.HashPassword(password); //admin.CreationDate = DateTime.Now; if (_db.Roles.Find(2) != null) { director.RoleId = 2; } _db.Managers.Add(director); _db.SaveChanges(); membershipUser = GetUser(email, false); return(membershipUser); #pragma warning disable CS0162 // Unreachable code detected Reception parent = new Reception(); #pragma warning restore CS0162 // Unreachable code detected parent.Email = email; parent.Password = Crypto.HashPassword(password); if (_db.Roles.Find(3) != null) { parent.RoleId = 3; } _db.Receptions.Add(parent); _db.SaveChanges(); membershipUser = GetUser(email, false); return(membershipUser); #pragma warning disable CS0162 // Unreachable code detected Teacher teacher = new Teacher(); #pragma warning restore CS0162 // Unreachable code detected teacher.Email = email; teacher.Password = Crypto.HashPassword(password); //admin.CreationDate = DateTime.Now; if (_db.Roles.Find(4) != null) { teacher.RoleId = 4; } _db.Teachers.Add(teacher); _db.SaveChanges(); membershipUser = GetUser(email, false); return(membershipUser); Student pupil = new Student(); pupil.Email = email; pupil.Password = Crypto.HashPassword(password); //admin.CreationDate = DateTime.Now; if (_db.Roles.Find(5) != null) { pupil.RoleId = 5; } _db.Students.Add(pupil); _db.SaveChanges(); membershipUser = GetUser(email, false); return(membershipUser); } } catch { return(null); } } return(null); }
public ActionResult Index(LogOnModel model, string returnUrl, string password) { if (ModelState.IsValid) { // поиск пользователя в бд Admin admin = null; Manager director = null; Teacher teacher = null; Reception parent = null; Student pupil = null; using (FastAndEasyEntities db = new FastAndEasyEntities()) { admin = db.Admins.FirstOrDefault(a => a.Email == model.UserName || a.UserName == model.UserName); director = db.Managers.FirstOrDefault(d => d.Email == model.UserName || d.UserName == model.UserName); teacher = db.Teachers.FirstOrDefault(t => t.Email == model.UserName || t.UserName == model.UserName); parent = db.Receptions.FirstOrDefault(p => p.Email == model.UserName || p.UserName == model.UserName); pupil = db.Students.FirstOrDefault(p => p.UserName == model.UserName || p.Email == model.UserName); } if (admin != null && Crypto.VerifyHashedPassword(admin.Password, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, true); return(RedirectToAction("Index", "Admin")); } else { ModelState.AddModelError("", "Пользователя с таким логином и паролем нет"); } if (director != null && Crypto.VerifyHashedPassword(director.Password, model.Password)) { if (Crypto.VerifyHashedPassword(director.Password, "1111")) { FormsAuthentication.SetAuthCookie(model.UserName, true); return(RedirectToAction("EditFirstTime", "ForDirector", new { id = director.Id })); } else { FormsAuthentication.SetAuthCookie(model.UserName, true); return(RedirectToAction("Index", "ForDirector", new { id = director.Id })); } } else { ModelState.AddModelError("", "Пользователя с таким логином и паролем нет"); } if (teacher != null && Crypto.VerifyHashedPassword(teacher.Password, model.Password)) { if (Crypto.VerifyHashedPassword(teacher.Password, "1111")) { FormsAuthentication.SetAuthCookie(model.UserName, true); return(RedirectToAction("EditFirstTime", "ForTeacher", new { id = teacher.Id })); } else { FormsAuthentication.SetAuthCookie(model.UserName, true); return(RedirectToAction("Index", "ForTeacher", new { id = teacher.Id })); } } else { ModelState.AddModelError("", "Пользователя с таким логином и паролем нет"); } if (parent != null && Crypto.VerifyHashedPassword(parent.Password, model.Password)) { if (Crypto.VerifyHashedPassword(parent.Password, "1111")) { FormsAuthentication.SetAuthCookie(model.UserName, true); return(RedirectToAction("Edit", "Reception", new { id = parent.Id })); } else { FormsAuthentication.SetAuthCookie(model.UserName, true); return(RedirectToAction("Index", "Reception", new { id = parent.Id })); } } else { ModelState.AddModelError("", "Пользователя с таким логином и паролем нет"); } if (pupil != null && Crypto.VerifyHashedPassword(pupil.Password, model.Password)) { if (Crypto.VerifyHashedPassword(pupil.Password, "1111")) { FormsAuthentication.SetAuthCookie(model.UserName, true); return(RedirectToAction("Edit", "Student", new { id = pupil.Id })); } else { FormsAuthentication.SetAuthCookie(model.UserName, true); return(RedirectToAction("Index", "Student", new { id = pupil.Id })); } } else { ModelState.AddModelError("", "Пользователя с таким логином и паролем нет"); } } return(View(model)); }