public async Task <IActionResult> PutInternship(int id, InternshipModel internshipModel) { //if (id != internship.InternshipId) //{ // return BadRequest(); //} try { var User_id = _customAuthManager.Tokens.FirstOrDefault().Value.Item3; // ToDO-> get User ID from Session User user = _context.Users.Find(User_id); Internship internship = new Internship(); // SetAddorUpdateIntern(Intership - TYPE, User =TYPE, Bool -TYPE) // the above method fill the object with user provided values and bool if it is for update internship.SetAddorUpdateIntern(internshipModel, user, true, id); _context.Internships.Update(internship); _context.SaveChanges(); return(Ok(internship)); } catch (Exception e) { return(BadRequest(e)); } }
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 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 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 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 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)); } }
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")); } }
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 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 string ConfirmEmail(string email, string token) { using (GlobalDBContext _context = new GlobalDBContext()) { // Check given Email and salt(token) are in the same user User theUser = _context.Users.FirstOrDefault(u => u.UserEmail == email && u.Salt == token); // if we found the user if (theUser != null) { // update the EmailVerified to True in the User table theUser.UserEmailVerified = true; _context.Users.Update(theUser); _context.SaveChanges(); return(theUser.UserEmail + "is Verifed. Login to our site."); } else { return("Link Expired"); } } }
public ActionResult <Internship> PostInternship(string wstring) { try { Internship intern; // ToDO-> get User ID from Session User user = _context.Users.Find(2); Internship internship = new Internship(); // SetAddorUpdateIntern(Intership - TYPE, User =TYPE, Bool -TYPE) // the above method fill the object with user provided values and bool if it is for update // internship.SetAddorUpdateIntern(intern, user); _context.Internships.Add(internship); _context.SaveChanges(); return(Ok(internship)); } catch (Exception e) { return(BadRequest(e)); } }
public ActionResult Create(Internship intern) { try { // ToDO-> get User ID from Session // geting menual user User user = _context.Users.Find(2); Internship internship = new Internship(); // SetAddorUpdateIntern(Intership - TYPE, User =TYPE, Bool -TYPE) // the above method fill the object with user provided values and bool if it is for update internship.SetAddorUpdateIntern(intern, user); _context.Internships.Add(internship); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public IActionResult CreateCourses(Course NewCourse) { // 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); var User_id = _customAuthManager.Tokens.FirstOrDefault().Value.Item3; var WhatIsThis = _customAuthManager.Tokens.FirstOrDefault().Value.Item1; var WhatIsThis1 = _customAuthManager.Tokens.FirstOrDefault().Value.Item2; //var WhatIsThis2 = _customAuthManager.Tokens.FirstOrDefault().Value.GetType; using (GlobalDBContext _context = new GlobalDBContext()) { Course nCourse = new Course(); //User user = _context.Users.Find(User_id); User user = _context.Users.Find(User_id); //this creates new course nCourse.CreateNewCourse(NewCourse, user); _context.Course.Add(nCourse); _context.SaveChanges(); ViewBag.Message = NewCourse.CourseTitle + " successfully created check the courses table to see if it has been created" + WhatIsThis + "//" + WhatIsThis1; } return(View()); }
// User should be initialized (setUser()) before using this method public void setUserCompany() { if (_user == null) { return; } using (GlobalDBContext _context = new GlobalDBContext()) { _company = _context.UserCompany.Include(r => r.User).FirstOrDefault(u => u.User.UserId == _user.UserId); if (_company == null) // If no record is found on user company { // inserting company with user ID UserCompany userCompany = new UserCompany(); User user = _context.Users.Find(_user.UserId); userCompany.User = user; _context.UserCompany.Add(userCompany); _context.SaveChanges(); _company = userCompany; } } }
public IActionResult InternshipApply(int?id, ApplyInternship fromData) { // the User is student // Make changes to AppliedInternship table. // make nortfication. try { using (GlobalDBContext _context = new GlobalDBContext()) { Internship intern = _context.Internships.Find(id); User user = _context.Users.Find(_customAuthManager.Tokens.FirstOrDefault().Value.Item3); AppliedInternship APP_Intern = new AppliedInternship(user, intern); _context.AppliedInternships.Add(APP_Intern); _context.SaveChanges(); return(View()); } } catch (Exception) { throw; } }
public IActionResult GeneralProfile(User UpdateDetails) { // 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); var User_id = _customAuthManager.Tokens.FirstOrDefault().Value.Item3; GlobalDBContext _context = new GlobalDBContext(); //assigns the new values to the updated ones _user.UserFirstName = UpdateDetails.UserFirstName; _user.UserLastName = UpdateDetails.UserLastName; _user.UserAddress = UpdateDetails.UserAddress; _user.UserCity = UpdateDetails.UserCity; _user.CreatedAt = UpdateDetails.CreatedAt; _user.UserState = UpdateDetails.UserState; _user.UserCountry = UpdateDetails.UserCountry; _user.UserZip = UpdateDetails.UserZip; _user.UserImage = UpdateDetails.UserImage; _user.UserGender = UpdateDetails.UserGender; _context.Users.Update(_user); _context.SaveChanges(); ViewBag.Message = _user.UserFirstName + " " + _user.UserLastName + " has been updated successfully. Check the Users table to see if it has been updated."; return(View(_user)); }
public IActionResult InternshipApply(int?id, ApplyInternship fromData) { // the User is student // Make changes to AppliedInternship table. // make nortfication. using (GlobalDBContext _context = new GlobalDBContext()) { string FinalCVPath; string FinalCLPath; string FinalCLString = null; // CV if (fromData.TemporaryCV != null && fromData.TemporaryCV.Length > 0) { string UserCVFolder = _env.WebRootPath + @"\uploads\UserCV\"; // File of code need to be Tested FinalCVPath = HelpersFunctions.StoreFile(UserCVFolder, fromData.TemporaryCV); } else { if (fromData.isCVExisting) { UserDocument Doc = _context.UserDocuments.Include(u => u.User).FirstOrDefault(p => p.User.UserId == _user.UserId && p.DocumentType == "CV"); FinalCVPath = Doc.DocumentPath; } else { FinalCVPath = null; } } // COVER Letter if (fromData.TemporaryCL != null && fromData.TemporaryCL.Length > 0) { string UserCLFolder = _env.WebRootPath + @"\uploads\UserCL\"; // File of code need to be Tested FinalCLPath = HelpersFunctions.StoreFile(UserCLFolder, fromData.TemporaryCL); } else { if (fromData.isCLExisting) { UserDocument Doc = _context.UserDocuments.Include(u => u.User).FirstOrDefault(p => p.User.UserId == _user.UserId && p.DocumentType == "CL"); FinalCLPath = Doc.DocumentPath; } else { FinalCLPath = null; if (fromData.isCLTextArea) { FinalCLString = fromData.WrittenCL; } else { FinalCLString = null; } } } Internship intern = _context.Internships.Find(id); // AppliedInternship constructor takes User and Internship object to create AppliedInternship object AppliedInternship APP_Intern = new AppliedInternship(_user, intern) { TempCVPath = FinalCVPath, TempCLPath = FinalCLPath, CoverLetterText = FinalCLString, EmployerStatus = "Pending" }; // Adding who applied the intership _context.AppliedInternships.Add(APP_Intern); _context.SaveChanges(); return(View()); } }