// GetMenuOptionsForUser -> return an dynamic object public static dynamic GetMenuOptionsForUser(int user_id, string path) { using (GlobalDBContext _context = new GlobalDBContext()) { User user = _context.Users.Include(p => p.Role).SingleOrDefault(x => x.UserId == user_id); using (StreamReader r = new StreamReader(path)) { string json = r.ReadToEnd(); var items = JsonConvert.DeserializeObject <dynamic>(json); foreach (var role in items["Roles"]) { try { string currentRole = FirstLetterToUpper(user.Role.RoleName); var itemObj = role[currentRole]; if (itemObj != null) { var MenuOptions = itemObj; return(MenuOptions); } } catch (Exception e) { Console.WriteLine(e); } } return(null); } } }
public IActionResult Index() { //Initialize initialize = new Initialize(); var db = GlobalDBContext.Instance(); //var db = CashierSystem_Service.GlobalDBContext.Instance(); //db.Add(new QP.CashierSystem_Model.Navs { Pid = 0, Area = "System", Controller = "home", Action = "index", IsNavi = true, IsHiddenMethod = false, CreateDate = DateTime.Now }); //db.SaveChanges(); //db.Add(new QP.CashierSystem_Model.Navs { Pid = 1, Area = "System", Controller = "home", Action = "index", IsNavi = true, IsHiddenMethod = false, CreateDate = DateTime.Now }); //db.SaveChanges(); //生成树形菜单 //var list = CashierSystem_Service.GlobalDBContext.Instance().Navs.Where( n => n.Area == "system").ToList(); //var rst = QP.Cashier.Utility.Array2Tree.ToTree(list); //调用写好的类,序列化成JSON格式 Cliet clite = new Cliet(); JieDian root = new JieDian(); //root.Name = "根节点"; //root.Id = 0; var list = new List <JieDian>(); clite.creatTheTree("0", root, out list); //根节点的parentBh值为"0" string json = Newtonsoft.Json.JsonConvert.SerializeObject(list); return(Json(json)); }
public IActionResult GeneralProfile(GeneralProfile generalProfile) { using (GlobalDBContext _context = new GlobalDBContext()) { if (generalProfile.UserImage != null && generalProfile.UserImage.Length > 0) { string uploadFolder = _env.WebRootPath + @"\uploads\UserImage\"; string uniqueFileName = Guid.NewGuid().ToString() + "_" + generalProfile.UserImage.FileName; string filePath = uploadFolder + uniqueFileName; generalProfile.UserImage.CopyTo(new FileStream(filePath, FileMode.Create)); // if new image is uploaded with other user info _user.AddFromAccountGeneralProfile(generalProfile, uniqueFileName); // Delete previous uploaded Image if (!String.IsNullOrEmpty(_user.UserImage)) { string imagePath = uploadFolder + _user.UserImage; Directory.Delete(imagePath); } } else { // Adding generalProfile attr to user without image _user.AddFromAccountGeneralProfile(generalProfile); } _context.Users.Update(_user); _context.SaveChanges(); GeneralProfile gen = new GeneralProfile(_user); string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); return View(gen); } }
public IActionResult Index() { // Display User name on the right-top corner - shows user is logedIN ViewData["LoggeduserName"] = new List <string>() { _user.UserFirstName + ' ' + _user.UserLastName, _user.UserImage }; // Geting Dashboard Menu from project/data/DashboardMenuOption.json into ViewData string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); using (GlobalDBContext _context = new GlobalDBContext()) { // Geting internshps student applied for using his/her userID var appliedInterns = _context.AppliedInternships.Include(i => i.Internship).Where(e => e.User == _user).ToList(); List <Internship> interns = new List <Internship>(); foreach (var appliedIntern in appliedInterns) { Internship theIntern = appliedIntern.Internship; interns.Add(theIntern); } } return(View()); }
/// <summary> /// 动态生成表格的数据 /// </summary> /// <param name="page"></param> /// <param name="rows"></param> /// <returns></returns> public JsonResult GetRoles(int?page, int?rows) { page = page == null ? 1 : page; //第几页 rows = rows == null ? 10 : rows; //行数 var db = GlobalDBContext.Instance(); var json = db.Staffs.Join(db.Operations, a => a.OperationID, b => b.OperationID, (a, b) => new { a.StaffBirth, a.StaffBirthType, a.StaffEntryTime, a.StaffIdentity, a.StaffName, a.StaffPhone, a.StaffSex, a.AcrossTheStore, a.StaffDuty, b.StaffCreateTime, b.StaffCreator, b.StaffUpdateTime, b.StaffModifyUser }).OrderBy(p => p.StaffName).Skip(Convert.ToInt32(rows) * Convert.ToInt32(page) - 1).Take(Convert.ToInt32(rows)); //DataGridJson obj = new DataGridJson(); //obj.rows = json; //obj.total = db.Staffs.Count(); return(Json(json)); }
public IActionResult Register(AccountRegister new_user) { using (GlobalDBContext _context = new GlobalDBContext()) { string _domainurl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; // ->TODO Validation check on clinet side using Jquery or JavaScript // Password hashed with extra layer of security string password = new_user.Password; CustomPasswordHasher pwd = new CustomPasswordHasher(); // increse the size to increase secuirty but lower performance string salt = pwd.CreateSalt(10); string hashed = pwd.HashPassword(password, salt); //new_user.Salt = salt; new_user.Password = hashed; // var errors = ModelState.Values.SelectMany(v => v.Errors); Role role = _context.Roles.Find(new_user.UserRole); User theUser = new User(); theUser.AddFromAccountRegsiter(new_user, role, salt); string uniqueToken = Guid.NewGuid().ToString("N").Substring(0, 6); theUser.UniqueToken = uniqueToken; _context.Users.Add(theUser); SendEmail email = new SendEmail(_emailSettings); string fullname = theUser.UserFirstName + " " + theUser.UserLastName; string msg = "Please verify you email account for the verification. Click on the link to verify :"; msg += _domainurl + "/Account/ConfirmEmail?email=" + theUser.UserEmail + "&token=" + theUser.UniqueToken; _context.SaveChanges(); email.SendEmailtoUser(fullname, theUser.UserEmail, "Email Verification", msg); ViewBag.Messsage = new_user.FirstName + " " + new_user.LastName + " successfully registered. A Email has been sent for the verfication."; } return(View()); }
public IActionResult Index() { // MENUAL ENTRY for ROLE using (GlobalDBContext _context = new GlobalDBContext()) { if (_context.Roles.ToList().Count != 0) { return(View()); } List <string> roles = new List <string>(3); roles.Add("Student"); roles.Add("Employer"); roles.Add("Teacher"); foreach (var role in roles) { Role r = new Role(); r.RoleName = role.ToLower(); _context.Roles.Add(r); _context.SaveChanges(); } } // ENDS return(View()); }
public IActionResult ConfirmEmail(string email, string token) { using (GlobalDBContext _context = new GlobalDBContext()) { // Recuqire Url encode - decode string encoded = System.Net.WebUtility.UrlEncode(token); // prevent cross site scripting. // Check given Email and salt(token) are in the same user User theUser = _context.Users.Include(r => r.Role).Where(u => u.UserEmail == email).FirstOrDefault <User>(); // if we found the user if (theUser.UniqueToken != token) { // update the EmailVerified to True in the User table theUser.UserEmailVerified = true; _context.Users.Update(theUser); _context.SaveChanges(); TempData["compeleteProfileUserId"] = JsonConvert.SerializeObject(theUser.UserId); ViewBag.message = theUser.UserEmail + " is Verifed. Now your can login to our site."; // Uncommnet below line to // login user came via email link. //_auth.Authenticate(theUser.UserEmail, theUser.Role.RoleName, theUser.UserId); return(View()); } else { return(Unauthorized()); } } }
public void CookieLogin() { // Check if Cookie Exists and if true create a Session var cookie = Request.Cookies["UserToken"]; if (cookie != null) { _httpContextAccessor.HttpContext.Session.SetString("UserToken", cookie); if (_customAuthManager.Tokens.Count != 0) { int userID = _customAuthManager.Tokens.FirstOrDefault(i => i.Key == cookie).Value.Item3; using (GlobalDBContext _context = new GlobalDBContext()) { LoggedIn_User = _context.Users.Find(userID); } } } else { string tokenFromSession = Response.HttpContext.Session.GetString("UserToken"); if (tokenFromSession != null) { int userID = _customAuthManager.Tokens.FirstOrDefault(i => i.Key == tokenFromSession).Value.Item3; using (GlobalDBContext _context = new GlobalDBContext()) { LoggedIn_User = _context.Users.Find(userID); } } } }
public IActionResult InternshipApply(int?id) { using (GlobalDBContext _context = new GlobalDBContext()) { Internship intern = _context.Internships.Find(id); } return(View()); }
//public async Task<IActionResult> InternshipsAsync([FromQuery]string search, int pageNumber = 0, int pageSize = 0) //{ // IEnumerable<Internship> model; // HttpResponseMessage resp; // string InternshipUrl = host + Internship_url; // try // { // if (!String.IsNullOrEmpty(search)) // { // InternshipUrl = InternshipUrl + "?search=" + search; // if (pageNumber != 0 && pageSize != 0) // { // InternshipUrl += "&pageNumber=" + pageNumber.ToString() + "&pageSize=" + pageSize.ToString(); // } // } // else // { // if (pageNumber != 0 && pageSize != 0) // { // InternshipUrl += "?pageNumber=" + pageNumber.ToString() + "&pageSize=" + pageSize.ToString(); // } // } // resp = await _client.GetAsync(InternshipUrl); // resp.EnsureSuccessStatusCode(); // string responseBody = await resp.Content.ReadAsStringAsync(); // var data = JsonConvert.DeserializeObject<dynamic>("[" + responseBody + "]"); // model = data[0]["data"].ToObject<IEnumerable<Internship>>(); // } // catch (Exception) // { // throw; // } // return View(model); //} public void setUser(string token) { using (GlobalDBContext _context = new GlobalDBContext()) { int userId = _customAuthManager.Tokens.FirstOrDefault(i => i.Key == token).Value.Item3; _user = _context.Users.Include(r => r.Role).FirstOrDefault(u => u.UserId == userId); } }
public InternshipsController(GlobalDBContext context, IHttpContextAccessor httpContextAccessor, ICustomAuthManager auth) { _customAuthManager = auth; _httpContextAccessor = httpContextAccessor; _context = context; _table = "Internships"; }
public IActionResult Qualifications(Qualification qualification) { using (GlobalDBContext _context = new GlobalDBContext()) { // additional codes? } return(View()); }
public IActionResult GeneralProfile(ProfileViewEmployer fromData) { using (GlobalDBContext _context = new GlobalDBContext()) { if (fromData.UserImage != null && fromData.UserImage.Length > 0) { string uploadFolder = _env.WebRootPath + @"\uploads\UserImage\"; // File of code need to be Tested //string file_Path = HelpersFunctions.StoreFile(uploadFolder, generalProfile.UserImage); string uniqueFileName = Guid.NewGuid().ToString() + "_" + fromData.UserImage.FileName; string filePath = uploadFolder + uniqueFileName; FileStream stream = new FileStream(filePath, FileMode.Create); fromData.UserImage.CopyTo(stream); stream.Dispose(); // Delete previous uploaded Image if (!String.IsNullOrEmpty(_user.UserImage)) { string imagePath = uploadFolder + _user.UserImage; if (System.IO.File.Exists(imagePath)) { // If file found, delete it System.IO.File.Delete(imagePath); Console.WriteLine("File deleted."); } } // if new image is uploaded with other user info _user.AddFromEmployerProfileView(fromData, uniqueFileName); } else { // Adding generalProfile attr to user without image _user.AddFromEmployerProfileView(fromData); } _context.Users.Update(_user); _context.SaveChanges(); fromData.UserImageName = _user.UserImage; // Display User name on the right-top corner - shows user is logedIN ViewData["LoggeduserName"] = new List <string>() { _user.UserFirstName + ' ' + _user.UserLastName, _user.UserImage }; // Geting Dashboard Menu from project/data/DashboardMenuOption.json into ViewData string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); //-------------------- END return(View(fromData)); } }
public IActionResult Index() { var db = GlobalDBContext.Instance(); Dictionary <string, string> keyValues = new Dictionary <string, string>(); foreach (var item in db.Shops) { keyValues.Add(item.ShopID, item.ShopName); } ViewData["SelectShop"] = new SelectList(keyValues, "Key", "Value"); return(View()); }
public void setUser() { string token = _httpContextAccessor.HttpContext.Session.GetString("UserToken"); if (_customAuthManager.Tokens.Count > 0) { int userId = _customAuthManager.Tokens.FirstOrDefault(i => i.Key == token).Value.Item3; using (GlobalDBContext _context = new GlobalDBContext()) { _user = _context.Users.Include(r => r.Role).FirstOrDefault(u => u.UserId == userId); } } }
internal void Delete(int id) { using (GlobalDBContext dBContext = new GlobalDBContext()) { Student student = dBContext.Student(true) .Where(s => s.ID == id) .FirstOrDefault(); if (student != null) { dBContext.Remove(student); dBContext.SaveChanges(); } } }
//public List<Student> GetStudents() //{ // using (GlobalDBContext dBContext = new GlobalDBContext()) // { // return dBContext.Student().ToList(); // } //} public void Write(string name, string lastname, string address, string phone) { using (GlobalDBContext dBContext = new GlobalDBContext()) { Student student = new Student() { Name = name, LastName = lastname, Address = address, Phone = phone }; dBContext.Add(student); dBContext.SaveChanges(); } }
public IActionResult DeleteUser() { using (GlobalDBContext _context = new GlobalDBContext()) { var User_id = _customAuthManager.Tokens.FirstOrDefault().Value.Item3; User user = _context.Users.Find(User_id); _context.Users.Remove(user); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } }
public IActionResult GeneralProfile() { // Display User name on the right-top corner - shows user is logedIN ViewData["LoggeduserName"] = _user.UserFirstName + ' ' + _user.UserLastName; // Geting Dashboard Menu from project/data/DashboardMenuOption.json into ViewData string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); using (GlobalDBContext _context = new GlobalDBContext()) { GeneralProfile gen = new GeneralProfile(_user); return View(gen); } }
public IActionResult LeftNav(string id) { var DbContext = GlobalDBContext.Instance(); Cliet clite = new Cliet(); JieDian root = new JieDian(); root.Name = "根节点"; root.Id = 0; var list = new List <JieDian>(); clite.creatTheTree(id, root, out list); //根节点的parentBh值为"0" string json = Newtonsoft.Json.JsonConvert.SerializeObject(list); return(Json(json)); }
public IActionResult Index() { // Display User name on the right-top corner - shows user is logedIN ViewData["LoggeduserName"] = _user.UserFirstName + ' ' + _user.UserLastName; // Geting Dashboard Menu from project/data/DashboardMenuOption.json into ViewData string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); using (GlobalDBContext _context = new GlobalDBContext()) { // Gets all internship created by the user ViewBag.IntershipsByLoginedInUser = _context.Internships.Where(e => e.User == _user).ToList(); return View(); } }
internal void UpDate(int ID, string name, string lastname, string address, string phone) { using (GlobalDBContext dbContext = new GlobalDBContext()) { Student student = dbContext.Student(true) .Where(s => s.ID == ID) .FirstOrDefault(); if (student != null) { student.Name = name; student.LastName = lastname; student.Address = address; student.Phone = phone; dbContext.SaveChanges(); } } }
public IActionResult Index([Bind("StaffName,StaffSex,StaffBirthType,StaffPhone,StaffBirth,StaffIdentity,JobNumber,Password,StaffDuty,StaffEntryTime,ShopID")] Staffs staffs) { var db = GlobalDBContext.Instance(); Random sj = new Random(); /// 用户登陆过后加入 操作人的信息 staffs.Roleds = "测试老板"; staffs.AuthorityID = sj.Next(1000, 10000).ToString(); staffs.StaffID = Guid.NewGuid().ToString(); staffs.WagesID = sj.Next(1000, 10000).ToString(); staffs.OperationID = sj.Next(1000, 10000).ToString(); HelpStaffs helpStaffs = new HelpStaffs(); var json = helpStaffs.AddEntity(staffs); return(Json(true)); }
//根据parentId获取相应的子目录集合 public Item[] GetTheItems(string parentId) { var db = GlobalDBContext.Instance(); var dr = db.Navs.Where(u => u.Parentid == parentId); List <Item> items = new System.Collections.Generic.List <Item>(); foreach (var item in dr) { Item i = new Item(); i.Id = int.Parse(item.Id); i.Name = item.NavName; i.IocCss = item.IcoCss; i.ParentId = int.Parse(item.Parentid); //i.ContentText = item.Descrition; items.Add(i); } return(items.ToArray()); }
public IActionResult GeneralProfile(ProfileViewStudent fromData) { // Display User name on the right-top corner - shows user is logedIN ViewData["LoggeduserName"] = new List <string>() { _user.UserFirstName + ' ' + _user.UserLastName, _user.UserImage }; // Geting Dashboard Menu from project/data/DashboardMenuOption.json into ViewData string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); // When Save button is clicked using (GlobalDBContext _context = new GlobalDBContext()) { if (fromData.UserImage != null && fromData.UserImage.Length > 0) { string uploadFolder = _env.WebRootPath + @"\uploads\UserImage\"; string uniqueFileName = Guid.NewGuid().ToString() + "_" + fromData.UserImage.FileName; string filePath = uploadFolder + uniqueFileName; fromData.UserImage.CopyTo(new FileStream(filePath, FileMode.Create)); // Delete previous uploaded Image if (!String.IsNullOrEmpty(_user.UserImage)) { string imagePath = uploadFolder + _user.UserImage; System.IO.File.Delete(imagePath); } // if new image is uploaded with other user info _user.AddFromStudentProfileView(fromData, uniqueFileName); } else { // Adding generalProfile attr to user without image _user.AddFromStudentProfileView(fromData); } _context.Users.Update(_user); _context.SaveChanges(); ProfileViewStudent gen = new ProfileViewStudent(_user); return(View(gen)); } }
public List <Student> GetStudents(string serachText) { using (GlobalDBContext dbContext = new GlobalDBContext()) { IQueryable <Student> query = dbContext.Student(); if (!string.IsNullOrEmpty(serachText)) { query = query.Where(c => c.Name.Contains(serachText) || c.LastName.Contains(serachText) || c.Address.Contains(serachText) || c.Phone.Contains(serachText) ); } query = query.OrderBy(student => student.Name); return(query.ToList()); } }
public IActionResult GeneralProfile() { // Display User name on the right-top corner - shows user is logedIN ViewData["LoggeduserName"] = new List <string>() { _user.UserFirstName + ' ' + _user.UserLastName, _user.UserImage }; // Geting Dashboard Menu from project/data/DashboardMenuOption.json into ViewData string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); //-------------------- END using (GlobalDBContext _context = new GlobalDBContext()) { ProfileViewEmployer userViewModel = new ProfileViewEmployer(_user); return(View(userViewModel)); } }
public IActionResult InternshipApply(int?id) { //CookieLogin(); //if (_user == null) //{ // return RedirectToAction("Login", "Account", new { redirect = "Home/Internship/" + id + "/Apply" }); // //return RedirectToAction("Login?redirectUrl=Home/Internship/"+id+"}/Apply", "Account"); //} //if(_user.Role.RoleName != "student") //{ // // To-Do Display message -> Your role does not suit the action. // return Unauthorized(); //} using (GlobalDBContext _context = new GlobalDBContext()) { Internship intern = _context.Internships.Find(id); ViewData["intern"] = intern; return(View()); } }
// setUser() method continue for above. public void setUser() { /// Access "UserToken" Session. /// NOTE: Session get created when user login with unique id. This id is also used to identify the user from number of Auth Tokens string token = _httpContextAccessor.HttpContext.Session.GetString("UserToken"); if (token == null) // if null user has not loggedIn { return; } using (GlobalDBContext _context = new GlobalDBContext()) { if (_customAuthManager.Tokens.Count > 0) { // check weather the unique id is in AuthManager int userId = _customAuthManager.Tokens.FirstOrDefault(i => i.Key == token).Value.Item3; // User is found in the AuthManager _user = _context.Users.Include(r => r.Role).FirstOrDefault(u => u.UserId == userId); } } }