public ActionResult ManageStaffEducationsModal(int id) { StaffDashboardViewModel sdVM = new StaffDashboardViewModel(); sdVM.SelectedStaffData.Staff = db.Staffs.Find(id); int i = 0; //get user's educations List <Education> selectedStaffEducations = db.Educations.Include(x => x.Staff).Where(x => x.Staff_ID == sdVM.SelectedStaffData.Staff.ID).ToList(); //Map user's educations to view model: ManageEducationsDataList foreach (var education in selectedStaffEducations) { ManageStaffEducationsViewModel manageEducationsVM = new ManageStaffEducationsViewModel(); manageEducationsVM.StaffID = education.Staff_ID; manageEducationsVM.School = education.School; manageEducationsVM.DegreeID = education.Degree_ID; manageEducationsVM.CompletedDate = education.Completed_Date; manageEducationsVM.HasEducation = true; manageEducationsVM.RemoveEducation = false; manageEducationsVM.StaffName = education.Staff.Staff_Name; manageEducationsVM.EducationID = education.ID; manageEducationsVM.CurrentListIndex = i; manageEducationsVM.IsNewSkill = false; i++; sdVM.ManageEducationsDataList.Add(manageEducationsVM); } ViewBag.DegSelectList = new SelectList(db.Adm_Degrees, "ID", "Degree"); ViewBag.ListDegrees = db.Adm_Degrees; return(PartialView("_staffEducationsModal", sdVM)); }
public ActionResult Dashboard() { StaffDashboardViewModel staffDBVM = new StaffDashboardViewModel(); staffDBVM.NumStaff = db.Staffs.Count(); staffDBVM.CompanyChart = getCompanyChartData(); return(View(staffDBVM)); }
public ActionResult ManageStaffSkillModal(int id) { StaffDashboardViewModel sdVM = new StaffDashboardViewModel(); sdVM.SelectedStaffData.Staff = db.Staffs.Find(id); //Load all proficiencies foreach (var proficiency in db.Adm_Proficiencies) { sdVM.AllSkillsData.Proficiencies.Add(proficiency); } //For each skill in the list of ALL skills foreach (var skill in db.Ref_Skills) { sdVM.AllSkillsData.Skills.Add(skill); //Create a view model, map to properties in Ref_Skills ManageSkillViewModel manageSkillVM = new ManageSkillViewModel(); manageSkillVM.SkillID = skill.ID; manageSkillVM.SkillName = skill.Skill; manageSkillVM.StaffID = sdVM.SelectedStaffData.Staff.ID; manageSkillVM.StaffSkillRadioButtonID = skill.ID + ", " + sdVM.SelectedStaffData.Staff.ID; //Get relevant skill data if user has the skill foreach (var mySkill in db.Staff_Skills.Where(x => x.Staff_ID == sdVM.SelectedStaffData.Staff.ID)) { if (mySkill.Skill_ID == skill.ID) { manageSkillVM.HasSkill = true; manageSkillVM.ProficiencyID = db.Staff_Skills.FirstOrDefault(x => x.Skill_ID == skill.ID).Proficiency_ID; manageSkillVM.ProficiencyName = db.Staff_Skills.FirstOrDefault(x => x.Skill_ID == skill.ID).Adm_Proficiency.Proficiency; manageSkillVM.RemoveSKill = false; } } sdVM.ManageSkillDataList.Add(manageSkillVM); //Add view model to list of view models } return(PartialView("_SkillModal", sdVM)); }
public ActionResult ManageStaffEducationsModal(StaffDashboardViewModel model) { string currentUserName = getCurrentUserFullName(); DateTime currentTime = System.DateTime.Now; DateTime nullDateTimeValue = new DateTime(0001, 1, 1, 12, 0, 0); if (ModelState.IsValid) { //create copy of data while we enumerate through the model List <ManageStaffEducationsViewModel> postIteratorCopy = model.ManageEducationsDataList; foreach (var editedEducation in model.ManageEducationsDataList) { //User wants to delete education if (editedEducation.RemoveEducation == true) { if (editedEducation.HasEducation == true) { Education educationToFind = new Education(); educationToFind = db.Educations.Where(x => x.ID == editedEducation.EducationID).SingleOrDefault(); db.Educations.Attach(educationToFind); db.Educations.Remove(educationToFind); } else if (editedEducation.IsNewSkill == true) { postIteratorCopy.Remove(editedEducation); } } //Check if user edited education else if (editedEducation.HasEducation == true && editedEducation.RemoveEducation == false) { Education educationFoundFromDb = new Education(); educationFoundFromDb = db.Educations.Where(x => x.ID == editedEducation.EducationID).SingleOrDefault(); //User modified a field in their existing Educations if (editedEducation.DegreeID != educationFoundFromDb.Degree_ID || editedEducation.School != educationFoundFromDb.School || editedEducation.CompletedDate != educationFoundFromDb.Completed_Date) { educationFoundFromDb.Degree_ID = editedEducation.DegreeID; educationFoundFromDb.School = editedEducation.School; educationFoundFromDb.Completed_Date = editedEducation.CompletedDate; educationFoundFromDb.Staff_ID = editedEducation.StaffID; educationFoundFromDb.Modified_By = currentUserName; educationFoundFromDb.Modified_On = currentTime; db.Educations.Attach(educationFoundFromDb); var entry = db.Entry(educationFoundFromDb); entry.State = EntityState.Modified; } } else if (editedEducation.HasEducation == false) { //User added new Education Education newEducation = new Education(); newEducation.Staff_ID = editedEducation.StaffID; newEducation.Degree_ID = editedEducation.DegreeID; newEducation.School = editedEducation.School; newEducation.Completed_Date = editedEducation.CompletedDate; newEducation.Created_By = currentUserName; newEducation.Created_On = currentTime; newEducation.Modified_By = currentUserName; newEducation.Modified_On = currentTime; db.Educations.Add(newEducation); } } } else { List <string> modelStateErrors = new List <string>(); foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { modelStateErrors.Add(error.ErrorMessage); } } } db.SaveChanges(); return(RedirectToAction("Index", "Staff")); }
public ActionResult ManageStaffSkillModal(StaffDashboardViewModel model) { if (ModelState.IsValid) { //Iterate over all skills user may have added/modified using client-filled form data foreach (var newStaffSkill in model.ManageSkillDataList) { //Staff has this skill and does not want to remove it (possible modification) if (newStaffSkill.HasSkill == true && newStaffSkill.RemoveSKill == false) { Staff_Skill skillToModify = new Staff_Skill(); skillToModify = db.Staff_Skills.Where(x => x.Staff_ID == newStaffSkill.StaffID) .Where(x => x.Skill_ID == newStaffSkill.SkillID).SingleOrDefault(); //User has modified the proficiency if (skillToModify.Proficiency_ID != newStaffSkill.ProficiencyID) { skillToModify.Proficiency_ID = newStaffSkill.ProficiencyID; skillToModify.Modified_By = getCurrentUserFullName(); skillToModify.Modified_On = System.DateTime.Now; db.Staff_Skills.Attach(skillToModify); var entry = db.Entry(skillToModify); entry.State = EntityState.Modified; } } //Staff has this skill and wants to remove it else if (newStaffSkill.HasSkill == true && newStaffSkill.RemoveSKill == true) { Staff_Skill skillToRemove = new Staff_Skill(); skillToRemove = db.Staff_Skills.Where(x => x.Staff_ID == newStaffSkill.StaffID) .Where(x => x.Skill_ID == newStaffSkill.SkillID).SingleOrDefault(); db.Staff_Skills.Attach(skillToRemove); db.Staff_Skills.Remove(skillToRemove); } //Staff does not have this skill else if (newStaffSkill.HasSkill == false) { //If the proficiency was selected, user wants to add this skill if (newStaffSkill.ProficiencyID != 0) { Staff_Skill newSkill = new Staff_Skill(); newSkill.Skill_ID = newStaffSkill.SkillID; newSkill.Staff_ID = newStaffSkill.StaffID; newSkill.Proficiency_ID = newStaffSkill.ProficiencyID; newSkill.Created_By = getCurrentUserFullName(); newSkill.Created_On = System.DateTime.Now; newSkill.Modified_By = getCurrentUserFullName(); newSkill.Modified_On = System.DateTime.Now; db.Staff_Skills.Add(newSkill); } } } } else { List <string> modelStateErrors = new List <string>(); foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { modelStateErrors.Add(error.ErrorMessage); } } } db.SaveChanges(); return(RedirectToAction("Index", "Staff")); }