public ActionResult PendingExpertRequests() { OrcaContext db = new OrcaContext(); // List<PendingExpertRequest> pendingRequests List <ExpertConsultant> pendingRequests = (from pen in db.ExpertConsultants where pen.ExpertStatus == ExpertStatus.Requested select pen).ToList(); List <PendingExpertRequest> pendingExpertRequests = new List <PendingExpertRequest>(); foreach (ExpertConsultant per in pendingRequests) { PendingExpertRequest userRequesting = new PendingExpertRequest(); int oid = per.OrcaUserID; OrcaUser ou = db.OrcaUsers.Find(oid); userRequesting.OrcaUserID = oid; userRequesting.OrcaUserName = ou.OrcaUserName; userRequesting.FirstName = ou.FirstName; userRequesting.LastName = ou.LastName; userRequesting.Email = ou.Email; userRequesting.PhoneNumber = ou.PhoneNumber; pendingExpertRequests.Add(userRequesting); } return(View(pendingExpertRequests)); }
public ActionResult PendingExpertRequestDetails([Bind(Exclude = "OrcaUserName,FirstName,LastName,Email,PhoneNumber", Include = "OrcaUserID, ExpertStatus")] PendingExpertRequest pendingExpertRequest) { int oid = pendingExpertRequest.OrcaUserID; if (ModelState.IsValid) { OrcaContext db = new OrcaContext(); ExpertConsultant expToUpdate = db.ExpertConsultants.Find(pendingExpertRequest.OrcaUserID); expToUpdate.ExpertStatus = pendingExpertRequest.ExpertStatus; db.Entry(expToUpdate).State = EntityState.Modified; db.SaveChanges(); //OrcaUserType.Consultant if (pendingExpertRequest.ExpertStatus == ExpertStatus.Approved) { OrcaUser requestingUser = db.OrcaUsers.Find(pendingExpertRequest.OrcaUserID); requestingUser.UserType = OrcaUserType.Consultant; db.Entry(requestingUser).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("PendingExpertRequests")); } return(View(pendingExpertRequest)); }
public ActionResult ChangeExpert([Bind(Exclude = "OrcaUserName,FirstName,LastName,Email,PhoneNumber", Include = "OrcaUserID,UserType,IsActive,IsAccountDeactivated")] ChangeExpert expToChange) { if (ModelState.IsValid) { OrcaContext db = new OrcaContext(); int oid = expToChange.OrcaUserID; OrcaUser changeUser = db.OrcaUsers.Find(oid); changeUser.UserType = expToChange.UserType; changeUser.IsAccountDeactivated = expToChange.IsAccountDeactivated; db.Entry(changeUser).State = EntityState.Modified; db.SaveChanges(); ExpertConsultant expCon = db.ExpertConsultants.Find(oid); expCon.IsActive = expToChange.IsActive; db.Entry(expCon).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("CurrentExperts")); } return(View()); }
public ActiveExperts PopulateList() { OrcaContext db = new OrcaContext(); // THIS IS A NASTY HACK BUT IT WILL WORK FOR NOW, it assumes that an expert consultant has added an expertise, otherwise the consultant can not be found in the list // NOTE: I need to figure out how to do the following section properly. I believe it has to do with using join, but I don't know enough about it so this will suffice for now. List <ConsultantExpertise> consultantExpertises = db.ConsultantExpertises.ToList(); Experts = new List <ActiveExpert>(); foreach (var exp in consultantExpertises) { ExpertConsultant expertConsultant = db.ExpertConsultants.Find(exp.OrcaUserID); if (expertConsultant != null && expertConsultant.IsActive) { OrcaUser orcaUser = db.OrcaUsers.Find(exp.OrcaUserID); ActiveExpert activeExpert = new ActiveExpert(); activeExpert.OrcaUserID = exp.OrcaUserID; activeExpert.OrcaUserName = orcaUser.OrcaUserName; activeExpert.FirstName = orcaUser.FirstName; activeExpert.LastName = orcaUser.LastName; activeExpert.TitleDegree = expertConsultant.TitleDegree; activeExpert.FieldOfExpertise = exp.FieldOfExpertise; Experts.Add(activeExpert); } } // NOTE: Need to figure out how to do the above section properly. I believe it can and should be done with a join but I don't know enough about it and this will suffice for now. return(this); }
public ActionResult Register([Bind(Include = "OrcaUserName,FirstName,LastName,Email,PhoneNumber,Password,ConfirmPassword")] Registration registrationInfo) { // convnention for making it easier to pass messages between controllers if (TempData["Message"] != null) { ViewBag.Message += (" " + TempData["Message"].ToString()); } OrcaContext db = new OrcaContext(); if (ModelState.IsValid) { var userExistQuery = from user in db.OrcaUsers where user.OrcaUserName == registrationInfo.OrcaUserName select user; if (userExistQuery.Any() == false)// make sure the username has not been taken { OrcaUser newOrcaUser = new OrcaUser(); newOrcaUser.OrcaPassword = new OrcaPassword(); // newOrcaUser.OrcaUserID = AUTOGENERATED newOrcaUser.OrcaUserName = registrationInfo.OrcaUserName; newOrcaUser.FirstName = registrationInfo.FirstName; newOrcaUser.LastName = registrationInfo.LastName; newOrcaUser.OrcaPassword.Password = registrationInfo.Password; newOrcaUser.Email = registrationInfo.Email; newOrcaUser.PhoneNumber = registrationInfo.PhoneNumber; newOrcaUser.IsAccountDeactivated = false; newOrcaUser.UserType = OrcaUserType.Consultee; db.OrcaUsers.Add(newOrcaUser); db.SaveChanges(); // not the best way to do it, but lets get the ID that was created. i havent tested it but i don't think that the OrcaUserID is coppied from the database to the newOrcaUser.OrcaUserID object. newOrcaUser = (from user in db.OrcaUsers where user.OrcaUserName == registrationInfo.OrcaUserName select user).First(); Session["OrcaUserID"] = newOrcaUser.OrcaUserID; Session["OrcaUserName"] = newOrcaUser.OrcaUserName; Session["FirstName"] = newOrcaUser.FirstName; Session["LastName"] = newOrcaUser.LastName; Session["UserType"] = newOrcaUser.UserType; TempData["Message"] = "You have successfully created a new account."; return(RedirectToAction("Index", "Consultee")); } else// if the username has been taken, instruct to choose different username { ViewBag.Message = "This User Name has already been taken. Please choose a different User Name for your account."; } } return(View(registrationInfo)); }
public ActionResult DeleteConfirmed(int id) { OrcaUser orcaUser = db.OrcaUsers.Find(id); db.OrcaUsers.Remove(orcaUser); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "OrcaUserID,OrcaUserName,FirstName,LastName,Email,PhoneNumber,IsAccountDeactivated,UserType")] OrcaUser orcaUser) { if (ModelState.IsValid) { db.Entry(orcaUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orcaUser)); }
public ActionResult Create([Bind(Include = "OrcaUserID,OrcaUserName,FirstName,LastName,Email,PhoneNumber,IsAccountDeactivated,UserType")] OrcaUser orcaUser) { if (ModelState.IsValid) { db.OrcaUsers.Add(orcaUser); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orcaUser)); }
public ActionResult ChangeExpert(int OrcaUserID) { OrcaContext db = new OrcaContext(); OrcaUser exp = db.OrcaUsers.Find(OrcaUserID); ChangeExpert expToChange = new ChangeExpert(); int oid = (int)OrcaUserID; expToChange.OrcaUserID = oid; expToChange.OrcaUserName = exp.OrcaUserName; expToChange.UserType = exp.UserType; string boolStrng = db.ExpertConsultants.Find(oid).IsActive.ToString().ToLower().Trim(); if (boolStrng == "true") { expToChange.IsActive = true; } else { expToChange.IsActive = false; } boolStrng = exp.IsAccountDeactivated.ToString().ToLower().Trim(); if (boolStrng == "true") { expToChange.IsAccountDeactivated = true; } else { expToChange.IsAccountDeactivated = false; } expToChange.FirstName = exp.FirstName; expToChange.LastName = exp.LastName; expToChange.Email = exp.Email; expToChange.PhoneNumber = exp.PhoneNumber; return(View(expToChange)); }
// GET: zzzTESTinCASEOrcaUsers/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OrcaUser orcaUser = db.OrcaUsers.Find(id); if (orcaUser == null) { return(HttpNotFound()); } return(View(orcaUser)); }
public UserProfile(int OrcaUserID) { OrcaContext db = new OrcaContext(); OrcaUser userInfo = db.OrcaUsers.Find(OrcaUserID); if (userInfo != null) { // fill in the info for the user this.OrcaUserID = OrcaUserID; this.OrcaUserName = userInfo.OrcaUserName; this.FirstName = userInfo.FirstName; this.LastName = userInfo.LastName; this.Email = userInfo.Email; this.PhoneNumber = userInfo.PhoneNumber; // check to see if user is a consultant expert if (userInfo.UserType == OrcaUserType.Consultant || userInfo.UserType == OrcaUserType.ConsultantAdmin) { ExpertConsultant consultantInfo = db.ExpertConsultants.Find(OrcaUserID); if (consultantInfo != null) { // using a dropdown but the db value is a bool, so set appropriately if (consultantInfo.IsActive) { this.IsActive = ActiveStatus.Yes; } else { this.IsActive = ActiveStatus.No; } this.TitleDegree = consultantInfo.TitleDegree; // this.FieldsOfExpertise = consultantInfo.ConsultantExpertises; this.FieldsOfExpertise = (from expertise in db.ConsultantExpertises where expertise.OrcaUserID == OrcaUserID select expertise).OrderBy(x => x.FieldOfExpertise).ToList(); this.KeyWordList = consultantInfo.KeyWordList; } } } }
public ActionResult PendingExpertRequestDetails(int?OrcaUserID) { OrcaContext db = new OrcaContext(); PendingExpertRequest pendingRequester = new PendingExpertRequest(); int oid = (int)OrcaUserID; OrcaUser ou = db.OrcaUsers.Find(oid); ExpertConsultant exp = db.ExpertConsultants.Find(oid); ou = db.OrcaUsers.Find(oid); pendingRequester.OrcaUserID = ou.OrcaUserID; pendingRequester.ExpertStatus = exp.ExpertStatus; pendingRequester.OrcaUserName = ou.OrcaUserName; pendingRequester.FirstName = ou.FirstName; pendingRequester.LastName = ou.LastName; pendingRequester.Email = ou.Email; pendingRequester.PhoneNumber = ou.PhoneNumber; return(View(pendingRequester)); }
protected override void Seed(OrcaContext context) { //base.Seed(context); // add a regular user for testing initialization OrcaUser generalUser = new OrcaUser(); generalUser.OrcaPassword = new OrcaPassword(); generalUser.OrcaUserName = "******"; generalUser.FirstName = "Test"; generalUser.LastName = "User"; generalUser.OrcaPassword.Password = "******"; generalUser.Email = "*****@*****.**"; generalUser.PhoneNumber = "3045432101"; generalUser.IsAccountDeactivated = false; generalUser.UserType = OrcaUserType.Consultee; context.OrcaUsers.Add(generalUser); context.SaveChanges(); // add a regular expert consultant for testing initialization OrcaUser expertUser = new OrcaUser(); expertUser.OrcaPassword = new OrcaPassword(); expertUser.OrcaUserName = "******"; expertUser.FirstName = "Test"; expertUser.LastName = "Expert"; expertUser.OrcaPassword.Password = "******"; expertUser.Email = "*****@*****.**"; expertUser.PhoneNumber = "1234567890"; expertUser.IsAccountDeactivated = false; expertUser.UserType = OrcaUserType.Consultant; context.OrcaUsers.Add(expertUser); context.SaveChanges(); ExpertConsultant expertUserConsultant = new ExpertConsultant(); expertUserConsultant.OrcaUserID = expertUser.OrcaUserID; expertUserConsultant.ExpertStatus = ExpertStatus.Approved; expertUserConsultant.IsActive = true; context.ExpertConsultants.Add(expertUserConsultant); context.SaveChanges(); ConsultantExpertise consultantExpertise = new ConsultantExpertise(); consultantExpertise.OrcaUserID = expertUserConsultant.OrcaUserID; consultantExpertise.FieldOfExpertise = "Computer Science"; context.ConsultantExpertises.Add(consultantExpertise); context.SaveChanges(); // add an admin expert consultant for testing initialization expertUser = new OrcaUser(); expertUser.OrcaPassword = new OrcaPassword(); expertUser.OrcaUserName = "******"; expertUser.FirstName = "Admin"; expertUser.LastName = "Expert"; expertUser.OrcaPassword.Password = "******"; expertUser.Email = "*****@*****.**"; expertUser.PhoneNumber = "1234567890"; expertUser.IsAccountDeactivated = false; expertUser.UserType = OrcaUserType.ConsultantAdmin; context.OrcaUsers.Add(expertUser); context.SaveChanges(); expertUserConsultant = new ExpertConsultant(); expertUserConsultant.OrcaUserID = expertUser.OrcaUserID; expertUserConsultant.ExpertStatus = ExpertStatus.Approved; expertUserConsultant.IsActive = true; context.ExpertConsultants.Add(expertUserConsultant); context.SaveChanges(); consultantExpertise = new ConsultantExpertise(); consultantExpertise.OrcaUserID = expertUserConsultant.OrcaUserID; consultantExpertise.FieldOfExpertise = "Software Engineering"; context.ConsultantExpertises.Add(consultantExpertise); context.SaveChanges(); }
public ActionResult Login([Bind(Include = "OrcaUserName,Password")] Login loginInfo) { // convnention for making it easier to pass messages between controllers if (TempData["Message"] != null) { ViewBag.Message += (" " + TempData["Message"].ToString()); } OrcaContext db = new OrcaContext(); if (ModelState.IsValid) { OrcaUser userQuery = null; // get the OrcaUser, if it doesn't exist this will throw an exception and userQuery will remain null try { userQuery = (from user in db.OrcaUsers where user.OrcaUserName == loginInfo.OrcaUserName select user).First(); } catch (Exception) { } if (userQuery != null)// check to see if the user account exists { userQuery.OrcaPassword = (from user in db.OrcaPasswords where user.OrcaUserID == userQuery.OrcaUserID select user).First(); // NOTE: // NOTE: Need to hash password later. // NOTE: if (userQuery.OrcaPassword.Password == loginInfo.Password)// check the password { // this is not the best way to do it, but knowledge of the language and api, or lack thereof dictates a sloppy work-around for now Session["OrcaUserID"] = userQuery.OrcaUserID; Session["OrcaUserName"] = userQuery.OrcaUserName; Session["FirstName"] = userQuery.FirstName; Session["LastName"] = userQuery.LastName; Session["UserType"] = userQuery.UserType; // following might be somewhat more proper but it is a pain in the arse to figure out when you don't know the language well enough and what i have below doesn't seem to work when trying to get the info out of it. i will note that using tempdata has no problem but then you have to keep saving the tempdata when going between controllers because otherwise it is cleared //Session["UserProfile"] = (new UserProfile(userQuery.OrcaUserID)) as UserProfile; TempData["Message"] = "You have successfully logged into your account."; switch (userQuery.UserType) { case OrcaUserType.Consultee: return(RedirectToAction("Index", "Consultee")); case OrcaUserType.Consultant: return(RedirectToAction("Index", "Consultant")); case OrcaUserType.ConsultantAdmin: return(RedirectToAction("Index", "ConsultantAdmin")); default: break; } } } } loginInfo.Password = "";// clear the password field so they know something was entered incorrectly ViewBag.Message = "The User Name or Password is incorrect."; return(View(loginInfo)); }
public static UserProfile ChangeUserProfileInfo(UserProfile profileChanges) { OrcaContext db = new OrcaContext(); OrcaUser orcaUser = db.OrcaUsers.Find(profileChanges.OrcaUserID); if (orcaUser != null) { // update any allowed changes that may have been made orcaUser.FirstName = profileChanges.FirstName; orcaUser.LastName = profileChanges.LastName; orcaUser.Email = profileChanges.Email; orcaUser.PhoneNumber = profileChanges.PhoneNumber; // update the database db.Entry(orcaUser).State = EntityState.Modified; db.SaveChanges(); if (orcaUser.UserType == OrcaUserType.Consultant || orcaUser.UserType == OrcaUserType.ConsultantAdmin) { ExpertConsultant expertConsultant = db.ExpertConsultants.Find(orcaUser.OrcaUserID); if (expertConsultant != null) { // update any allowed changes that may have been made expertConsultant.TitleDegree = profileChanges.TitleDegree; expertConsultant.KeyWordList = profileChanges.KeyWordList; // IsActive is done this way to allow a drop down list for the profile view if (profileChanges.IsActive == ActiveStatus.Yes) { expertConsultant.IsActive = true; } else { expertConsultant.IsActive = false; } // update the database db.Entry(expertConsultant).State = EntityState.Modified; db.SaveChanges(); // this isn't pretty, but i was doing it this way while trying to figure out where a problem was occuring. since its done, i'll leave it alone for now, after all, it is a prototype // add the new field of expertise if it is entered if (!(String.IsNullOrEmpty(profileChanges.FieldToAdd) || String.IsNullOrWhiteSpace(profileChanges.FieldToAdd)))// make sure something was entered in FieldToAdd { // get a list of current expertises List <ConsultantExpertise> userExpertises = (from expertise in db.ConsultantExpertises where expertise.OrcaUserID == profileChanges.OrcaUserID select expertise).ToList(); if (userExpertises.Count() <= 0 || userExpertises.All(ex => ex.FieldOfExpertise != profileChanges.FieldToAdd))// make sure that we aren't duplicating any expertises { ConsultantExpertise newField = new ConsultantExpertise(); newField.OrcaUserID = profileChanges.OrcaUserID; newField.FieldOfExpertise = profileChanges.FieldToAdd; db.ConsultantExpertises.Add(newField); db.SaveChanges(); } } } } } return(profileChanges); }