public async Task <ActionResult> Edit(PersonnelProfileViewModel personnelViewModel) { if (ModelState.IsValid) { var resultData = await _personnelBusinessService.UpdatePersonnel(personnelViewModel.Personnel); if (resultData.Succeeded) { var editUser = UserManager.FindByPersonnelId(personnelViewModel.Personnel.PersonnelId); editUser.Email = personnelViewModel.Personnel.Email; var result = UserManager.Update(editUser); if (result.Succeeded) { return(RedirectToAction("Index")); } } ModelState.AddModelError("", resultData.Exception); foreach (var error in resultData.Errors) { ModelState.AddModelError("", error); } } var viewModel = new PersonnelProfileViewModel { Personnel = personnelViewModel.Personnel }; return(View(viewModel)); }
public ActionResult Edit(PersonnelProfileViewModel personnelViewModel) { if (ModelState.IsValid) { personnelViewModel.Personnel = NidanBusinessService.UpdatePersonnel(UserOrganisationId, personnelViewModel.Personnel); var editUser = UserManager.FindByPersonnelId(personnelViewModel.Personnel.PersonnelId); editUser.Email = personnelViewModel.Personnel.Email; var result = UserManager.Update(editUser); if (result.Succeeded) { return(RedirectToAction("Index")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } var viewModel = new PersonnelProfileViewModel { Personnel = personnelViewModel.Personnel }; return(View(viewModel)); }
public async Task <ActionResult> Create(PersonnelProfileViewModel personnelViewModel) { // check if user with this email already exists for the current organisation // var centres = EgharpayBusinessService.RetrieveCentres(UserOrganisationId, e => true); var userExists = UserManager.FindByEmail(personnelViewModel.Personnel.Email); // personnelViewModel.Centres = new SelectList(centres, "CentreId", "Name"); if (userExists != null) { ModelState.AddModelError("", string.Format("An account already exists for the email address {0}", personnelViewModel.Personnel.Email)); } if (ModelState.IsValid) { //Create Personnel var result = await _personnelBusinessService.CreatePersonnel(personnelViewModel.Personnel); if (result.Succeeded) { // CreateUserAndRole(personnelViewModel.Personnel); return(RedirectToAction("Index")); } ModelState.AddModelError("", result.Exception); foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } return(View(personnelViewModel)); }
public ActionResult Create(PersonnelProfileViewModel personnelViewModel) { // check if user with this email already exists for the current organisation var userExists = UserManager.FindByEmail(personnelViewModel.Personnel.Email); if (userExists != null) { ModelState.AddModelError("", string.Format("An account already exists for the email address {0}", personnelViewModel.Personnel.Email)); } if (ModelState.IsValid) { //Create Personnel personnelViewModel.Personnel = NidanBusinessService.CreatePersonnel(UserOrganisationId, personnelViewModel.Personnel); var result = CreateUserAndRole(personnelViewModel.Personnel); if (result.Succeeded) { return(RedirectToAction("Index")); } //delete the orphaned personnel & employment records NidanBusinessService.DeletePersonnel(UserOrganisationId, personnelViewModel.Personnel.PersonnelId); foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } return(View(personnelViewModel)); }
public new ActionResult Profile(int id) { var organisationId = UserOrganisationId; var personnelId = UserPersonnelId; var personnel = HRBusinessService.RetrievePersonnel(organisationId, id); if (personnel == null) { return(HttpNotFound()); } var isAdmin = User.IsInAnyRoles("Admin"); var firstOrDefault = personnel.Employments.FirstOrDefault(); if (firstOrDefault != null && (firstOrDefault.TerminationDate.HasValue && firstOrDefault.TerminationDate <= _defaultDate)) { ModelState.AddModelError("TerminatedError", "Employee terminated , please contact your HR administrator."); } if (personnel.CurrentAbsenceTypeEntitlements == null || !personnel.CurrentAbsenceTypeEntitlements.Any()) { ModelState.AddModelError("EntitlementError", "Absence entitlements may not been correctly configured, please contact your HR administrator."); } var viewModel = new PersonnelProfileViewModel { Personnel = personnel, Permissions = HRBusinessService.RetrievePersonnelPermissions(isAdmin, organisationId, UserPersonnelId, id) }; return(View(viewModel)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var personnel = HRBusinessService.RetrievePersonnel(UserOrganisationId, id.Value); if (personnel == null) { return(HttpNotFound()); } personnel.Email = UserManager.FindByPersonnelId(personnel.PersonnelId)?.Email; var isAdmin = User.IsInAnyRoles("Admin"); var employment = HRBusinessService.RetrieveEmployment(UserOrganisationId, id.Value, _defaultDate); var approvalEntityTypeAssignments = HRBusinessService.ApprovalEntityTypeAssignments(UserOrganisationId, id.Value); var approvalModels = HRBusinessService.RetrieveApprovalModels(UserOrganisationId); var permissions = HRBusinessService.RetrievePersonnelPermissions(isAdmin, UserOrganisationId, UserPersonnelId, id); var viewModel = new PersonnelProfileViewModel { Countries = new SelectList(HRBusinessService.RetrieveCountries(UserOrganisationId, null, null).Items, "CountryId", "Name", personnel.CountryId), Personnel = personnel, SelectedDepartmentIds = employment?.EmploymentDepartments.Select(d => d.DepartmentId).ToList(), SelectedTeamIds = employment?.EmploymentTeams.Select(t => t.TeamId).ToList(), ApprovalEntityTypeAssignments = approvalEntityTypeAssignments, ApprovalModels = approvalModels, Permissions = permissions }; return(View(viewModel)); }
public new ActionResult Profile(int id) { var organisationId = UserOrganisationId; var personnelId = UserPersonnelId; var personnel = NidanBusinessService.RetrievePersonnel(UserOrganisationId, id); if (personnel == null) { return(HttpNotFound()); } var isAdmin = User.IsInAnyRoles("Admin"); List <int> selectedCompanyIds = null; List <int> selectedDepartmentIds = null; List <int> selectedDivisionIds = null; if (!isAdmin) { } var viewModel = new PersonnelProfileViewModel { Personnel = personnel, Permissions = NidanBusinessService.RetrievePersonnelPermissions(isAdmin, UserOrganisationId, UserPersonnelId, id), //PhotoBytes = NidanBusinessService.RetrievePhoto(organisationId, id) }; return(View(viewModel)); }
public ActionResult Create() { var organisationId = UserOrganisationId; var centres = NidanBusinessService.RetrieveCentres(organisationId, e => true); var roles = NidanBusinessService.RetrieveAspNetRoles(organisationId, e => true); var viewModel = new PersonnelProfileViewModel { Centres = new SelectList(centres, "CentreId", "Name"), Roles = new SelectList(roles, "Id", "Name") }; return(View(viewModel)); }
public async Task <ActionResult> Edit(int personnelId) { if (!User.Identity.IsAuthenticated) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var personnel = await _personnelBusinessService.RetrievePersonnel(personnelId); if (personnel == null) { return(HttpNotFound()); } var viewModel = new PersonnelProfileViewModel { Personnel = personnel.Entity }; return(View(viewModel)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var personnel = NidanBusinessService.RetrievePersonnel(UserOrganisationId, id.Value); if (personnel == null) { return(HttpNotFound()); } personnel.Email = UserManager.FindByPersonnelId(personnel.PersonnelId)?.Email; var viewModel = new PersonnelProfileViewModel { Personnel = personnel }; return(View(viewModel)); }
public ActionResult Create() { var viewModel = new PersonnelProfileViewModel { Personnel = new Personnel { OrganisationId = UserOrganisationId, DOB = DateTime.Today, Title = "Mr", Forenames = "A", Surname = "B", Email = string.Format("{0}@hr.com", Guid.NewGuid()), Address1 = "Address1", Postcode = "POST CODE", Telephone = "12345678", NINumber = "NZ1234567", }, }; return(View(viewModel)); }
public async Task <ActionResult> Profile(int id) { var personnel = await _personnelBusinessService.RetrievePersonnel(UserOrganisationId, id); if (personnel == null) { return(HttpNotFound()); } var isAdmin = User.IsInAnyRoles("Admin"); if (!isAdmin) { } var viewModel = new PersonnelProfileViewModel { Personnel = personnel, //Permissions = EgharpayBusinessService.RetrievePersonnelPermissions(isAdmin, UserOrganisationId, UserPersonnelId, id), //PhotoBytes = EgharpayBusinessService.RetrievePhoto(organisationId, id) }; return(View(viewModel)); }
public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var personnel = await _personnelBusinessService.RetrievePersonnel(UserOrganisationId, id.Value); if (personnel == null) { return(HttpNotFound()); } // var centres = EgharpayBusinessService.RetrieveCentres(UserOrganisationId, e => true); personnel.Email = UserManager.FindByPersonnelId(personnel.PersonnelId)?.Email; var viewModel = new PersonnelProfileViewModel { // Centres = new SelectList(centres, "CentreId", "Name"), Personnel = personnel }; return(View(viewModel)); }
public ActionResult Create(PersonnelProfileViewModel personnelViewModel) { // check if user with this email already exists for the current organisation var organisationId = UserOrganisationId; var centres = NidanBusinessService.RetrieveCentres(organisationId, e => true); var userExists = UserManager.FindByEmail(personnelViewModel.Personnel.Email); var roleId = NidanBusinessService.RetrieveAspNetRoles(organisationId, e => e.Id == personnelViewModel.Role).FirstOrDefault().Name; personnelViewModel.Centres = new SelectList(centres, "CentreId", "Name"); if (userExists != null) { ModelState.AddModelError("", string.Format("An account already exists for the email address {0}", personnelViewModel.Personnel.Email)); } if (ModelState.IsValid) { //Create Personnel personnelViewModel.Personnel.CentreId = personnelViewModel.Personnel.CentreId == 0 ? UserCentreId : personnelViewModel.Personnel.CentreId; personnelViewModel.Personnel = NidanBusinessService.CreatePersonnel(UserOrganisationId, personnelViewModel.Personnel); //var trainer = NidanBusinessService.CreateTrainer //create personnel //var personnel = new Personnel(){set all mandatory field like forename } //CreateTrainerUserAndRole(personnel) var result = CreateUserAndRole(personnelViewModel.Personnel, roleId); if (result.Succeeded) { return(RedirectToAction("Index")); } //delete the orphaned personnel & employment records NidanBusinessService.DeletePersonnel(UserOrganisationId, personnelViewModel.Personnel.PersonnelId); foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } return(View(personnelViewModel)); }
public ActionResult Create() { var centres = EgharpayBusinessService.RetrieveCentres(UserOrganisationId, e => true); var viewModel = new PersonnelProfileViewModel { Centres = new SelectList(centres, "CentreId", "Name"), Personnel = new Personnel { OrganisationId = UserOrganisationId, DOB = DateTime.Today, Title = "Mr", Forenames = "A", Surname = "B", Email = string.Format("{0}@hr.com", Guid.NewGuid()), Address1 = "Address1", Postcode = "POST CODE", Telephone = "12345678", }, }; return(View(viewModel)); }
public async Task <ActionResult> Profile(bool?profileUpdated) { var id = UserPersonnelId; if (User.IsPersonnel() && !await AuthorizationService.AuthorizeAsync((ClaimsPrincipal)User, id, Policies.Resource.Personnel.ToString())) { return(HttpForbidden()); } if (id == 0) { return(RedirectToAction("Login", "Account")); } var personnel = await _personnelBusinessService.RetrievePersonnel(id); if (personnel == null) { return(HttpNotFound()); } var viewModel = new PersonnelProfileViewModel { Personnel = personnel.Entity, PersonnelId = personnel.Entity.PersonnelId, ProfileUpdated = profileUpdated ?? false //Permissions = EgharpayBusinessService.RetrievePersonnelPermissions(isAdmin, UserOrganisationId, UserPersonnelId, id), //PhotoBytes = EgharpayBusinessService.RetrievePhoto(organisationId, id) }; if (User.IsSeller()) { var seller = await _sellerBusinessService.RetrieveSellerByPersonnelId(personnel.Entity.PersonnelId); viewModel.IsSellerApproved = seller.ApprovalStateId == (int)SellerApprovalState.Approved; } return(View(viewModel)); }
public async Task <ActionResult> Edit(PersonnelProfileViewModel personnelViewModel) { if (ModelState.IsValid) { var resultData = await _personnelBusinessService.UpdatePersonnel(personnelViewModel.Personnel); if (resultData.Succeeded) { personnelViewModel.ProfileUpdated = resultData.Succeeded; return(RedirectToAction("Profile", new { profileUpdated = personnelViewModel.ProfileUpdated })); } ModelState.AddModelError("", resultData.Exception); foreach (var error in resultData.Errors) { ModelState.AddModelError("", error); } } var viewModel = new PersonnelProfileViewModel { Personnel = personnelViewModel.Personnel }; return(View(viewModel)); }
public ActionResult Create() { var isAdmin = User.IsInAnyRoles("Admin"); var organisationId = UserOrganisationId; var countries = HRBusinessService.RetrieveCountries(organisationId, null, null).Items; var reportsTo = HRBusinessService.RetrieveReportsToPersonnel(organisationId, 0); var employmentTypes = HRBusinessService.RetrieveEmploymentTypes(organisationId); var absencePolices = HRBusinessService.RetrieveAbsencePolices(organisationId); var publicHolidayPolices = HRBusinessService.RetrievePublicHolidayPolices(organisationId); var companyBuilding = HRBusinessService.RetrieveEmploymentCompanyBuilding(organisationId); var defaultSelected = HRBusinessService.RetrieveEmploymentCompanyBuilding(organisationId).FirstOrDefault(); var jobTitleJobgrades = HRBusinessService.RetrieveJobTitleJobGrade(organisationId).ToList(); var defaultSelectedJobTitleJobgrades = jobTitleJobgrades.FirstOrDefault(); var approvalEntityTypeAssignments = HRBusinessService.ApprovalEntityTypeAssignments(UserOrganisationId, 0); var approvalModels = HRBusinessService.RetrieveApprovalModels(UserOrganisationId); var permissions = HRBusinessService.RetrievePersonnelPermissions(isAdmin, UserOrganisationId, UserPersonnelId, 0); if (defaultSelected == null) { ModelState.AddModelError("EmploymentError", "Assign Site Building to Company"); } if (defaultSelectedJobTitleJobgrades == null) { ModelState.AddModelError("EmploymentError", "Assign JobTitle to JobGrade"); } var viewModel = new PersonnelProfileViewModel { Countries = new SelectList(countries, "CountryId", "Name"), Personnel = new Personnel { OrganisationId = organisationId, DOB = DateTime.Today, //Title = "Mr", //Forenames = "A", //Surname = "B", //Email = string.Format("{0}@hr.com", Guid.NewGuid()), //Address1 = "Address1", //Postcode = "POST CODE", //Telephone = "12345678", //NINumber = "NZ1234567", }, EmploymentViewModel = new EmploymentViewModel { ReportsTo = new SelectList(reportsTo, "PersonnelId", "Fullname"), AbsencePolicy = new SelectList(absencePolices, "AbsencePolicyId", "Name"), PublicHolidayPolicy = new SelectList(publicHolidayPolices, "PublicHolidayPolicyId", "Name"), Employment = new Employment { OrganisationId = UserOrganisationId, StartDate = DateTime.Today, CompanyId = defaultSelected?.Company.CompanyId ?? 0, BuildingId = defaultSelected?.Building.BuildingId ?? 0, JobGradeId = defaultSelectedJobTitleJobgrades?.JobGradeId ?? 0, JobTitleId = defaultSelectedJobTitleJobgrades?.JobTitleId ?? 0 }, EmploymentType = new SelectList(employmentTypes, "EmploymentTypeId", "Name"), EmploymentCompanyBuildinglist = companyBuilding, SelectedBuildingId = defaultSelected?.Company.CompanyId.ToString() ?? string.Empty, JobTitleJobGrades = jobTitleJobgrades, SelectedCompanyId = defaultSelected?.Building.BuildingId.ToString() ?? string.Empty, SelectedJobTitleId = defaultSelectedJobTitleJobgrades?.JobTitle.JobTitleId.ToString() ?? string.Empty, SelectedJobGradeId = defaultSelectedJobTitleJobgrades?.JobGrade.JobGradeId.ToString() ?? string.Empty, SelectedDepartmentIds = new List <int> { }, // HERE AS AN EXAMPLE OF PRE SELECTED DATA (ie when editing) SelectedTeamIds = new List <int> { } // HERE AS AN EXAMPLE OF PRE SELECTED DATA (ie when editing) }, ApprovalEntityTypeAssignments = approvalEntityTypeAssignments, ApprovalModels = approvalModels, Permissions = permissions }; return(View(viewModel)); }
public ActionResult Edit(PersonnelProfileViewModel personnelViewModel) { if (ModelState.IsValid) { personnelViewModel.Personnel = HRBusinessService.UpdatePersonnel(UserOrganisationId, personnelViewModel.Personnel); if (personnelViewModel.ApprovalEntityTypeAssignments != null) { foreach (var approvalEntityTypeAssignment in personnelViewModel.ApprovalEntityTypeAssignments) { PersonnelApprovalModel personnelApprovalModel = new PersonnelApprovalModel { PersonnelId = personnelViewModel.Personnel.PersonnelId, ApprovalEntityTypeId = approvalEntityTypeAssignment.ApprovalEntityId, ApprovalModelId = approvalEntityTypeAssignment.ApprovalModelId, PersonnelApprovalModelId = approvalEntityTypeAssignment.PersonnelApprovalModelId }; if (personnelApprovalModel.PersonnelApprovalModelId == 0) { HRBusinessService.CreatePersonnelApprovalModel(UserOrganisationId, personnelApprovalModel); } else if (personnelApprovalModel.ApprovalModelId == 0) { HRBusinessService.DeletePersonnelApprovalModel(UserOrganisationId, personnelApprovalModel.PersonnelApprovalModelId); } else { HRBusinessService.UpdatePersonnelApprovalModel(UserOrganisationId, personnelApprovalModel); } } } var editUser = UserManager.FindByPersonnelId(personnelViewModel.Personnel.PersonnelId); editUser.Email = personnelViewModel.Personnel.Email; var result = UserManager.Update(editUser); if (result.Succeeded) { if (User.IsInRole("User")) { return(RedirectToAction("Profile", "Personnel", new { id = personnelViewModel.Personnel.PersonnelId })); } else { return(RedirectToAction("Index")); } } foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } var approvalEntityTypeAssignments = HRBusinessService.ApprovalEntityTypeAssignments(UserOrganisationId, personnelViewModel.Personnel.PersonnelId); var approvalModels = HRBusinessService.RetrieveApprovalModels(UserOrganisationId); var viewModel = new PersonnelProfileViewModel { Countries = new SelectList(HRBusinessService.RetrieveCountries(UserOrganisationId, null, null).Items, "CountryId", "Name"), Personnel = personnelViewModel.Personnel, ApprovalEntityTypeAssignments = approvalEntityTypeAssignments, ApprovalModels = approvalModels }; return(View(viewModel)); }
public ActionResult Create(PersonnelProfileViewModel personnelViewModel) { try { var organisationId = UserOrganisationId; // check if user with this email already exists for the current organisation var userExists = UserManager.FindByEmail(personnelViewModel.Personnel.Email); if (userExists != null) { ModelState.AddModelError("", string.Format("An account already exists for the email address {0}", personnelViewModel.Personnel.Email)); } var modelError = ModelState.Values.Where(e => e.Errors.Count > 0); if (ModelState.IsValid) { personnelViewModel.Personnel = HRBusinessService.CreatePersonnel(organisationId, personnelViewModel.Personnel, personnelViewModel.EmploymentViewModel.Employment, personnelViewModel.EmploymentViewModel.WorkingPatternDays.ToList(), personnelViewModel.EmploymentViewModel.SelectedDepartmentIds, personnelViewModel.EmploymentViewModel.SelectedTeamIds); var result = CreateUserAndRole(personnelViewModel.Personnel); if (personnelViewModel.ApprovalEntityTypeAssignments != null) { foreach (var approvalEntityTypeAssignment in personnelViewModel.ApprovalEntityTypeAssignments) { PersonnelApprovalModel personnelApprovalModel = new PersonnelApprovalModel { PersonnelId = personnelViewModel.Personnel.PersonnelId, ApprovalEntityTypeId = approvalEntityTypeAssignment.ApprovalEntityId, ApprovalModelId = approvalEntityTypeAssignment.ApprovalModelId, PersonnelApprovalModelId = approvalEntityTypeAssignment.PersonnelApprovalModelId }; HRBusinessService.CreatePersonnelApprovalModel(UserOrganisationId, personnelApprovalModel); } } if (result.Succeeded) { return(RedirectToAction("Index")); } //delete the orphaned personnel & employment records HRBusinessService.DeletePersonnel(organisationId, personnelViewModel.Personnel.PersonnelId); foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } var jobTitleJobgrades = HRBusinessService.RetrieveJobTitleJobGrade(organisationId); var defaultSelectedJobTitleJobgrades = jobTitleJobgrades.FirstOrDefault(); var countries = HRBusinessService.RetrieveCountries(organisationId, null, null).Items; var reportsTo = HRBusinessService.RetrieveReportsToPersonnel(organisationId, 0); var absencePolices = HRBusinessService.RetrieveAbsencePolices(organisationId); var publicHolidayPolices = HRBusinessService.RetrievePublicHolidayPolices(organisationId); var companyBuilding = HRBusinessService.RetrieveEmploymentCompanyBuilding(organisationId); var employmentTypes = HRBusinessService.RetrieveEmploymentTypes(organisationId); var approvalEntityTypeAssignments = HRBusinessService.ApprovalEntityTypeAssignments(UserOrganisationId, 0); var approvalModels = HRBusinessService.RetrieveApprovalModels(UserOrganisationId); var viewModel = new PersonnelProfileViewModel { Countries = new SelectList(countries, "CountryId", "Name"), Personnel = personnelViewModel.Personnel, EmploymentViewModel = new EmploymentViewModel { ReportsTo = new SelectList(reportsTo, "PersonnelId", "Fullname", personnelViewModel.EmploymentViewModel.Employment.ReportsToPersonnelId), EmploymentType = new SelectList(employmentTypes, "EmploymentTypeId", "Name", personnelViewModel.EmploymentViewModel.Employment.EmploymentTypeId), AbsencePolicy = new SelectList(absencePolices, "AbsencePolicyId", "Name"), PublicHolidayPolicy = new SelectList(publicHolidayPolices, "PublicHolidayPolicyId", "Name"), JobTitleJobGrades = jobTitleJobgrades, Employment = personnelViewModel.EmploymentViewModel.Employment, WorkingPatternDays = personnelViewModel.EmploymentViewModel.WorkingPatternDays, EmploymentCompanyBuildinglist = companyBuilding, SelectedDepartmentIds = personnelViewModel.EmploymentViewModel.SelectedDepartmentIds, SelectedTeamIds = personnelViewModel.EmploymentViewModel.SelectedTeamIds, SelectedBuildingId = personnelViewModel.EmploymentViewModel.Employment.BuildingId.ToString(), SelectedCompanyId = personnelViewModel.EmploymentViewModel.Employment.CompanyId.ToString(), SelectedJobTitleId = defaultSelectedJobTitleJobgrades.JobTitle.JobTitleId.ToString(), SelectedJobGradeId = defaultSelectedJobTitleJobgrades.JobGrade.JobGradeId.ToString() }, ApprovalEntityTypeAssignments = approvalEntityTypeAssignments, ApprovalModels = approvalModels }; return(View(viewModel)); } catch (Exception ex) { return(this.JsonNet(ex)); } }