public ActionResult SearchStaffDeputyNominatedManagers() { // Get the updated model var model = GetUpdatedModel(); // Clear model state to prevent validation ModelState.Clear(); //Set flags false SetFlagsFalse(model); // Create service instance IUcbService sc = UcbService; try { StaffNominatedManagerSearchVMDC searchCritera = new StaffNominatedManagerSearchVMDC(); searchCritera.FirstName = model.DeputyNominatedManagerFirstNameSearch; searchCritera.LastName = model.DeputyNominatedManagerLastNameSearch; searchCritera.IsDeputyNominatedManager = true; searchCritera.IsNominatedManager = false; StaffNominatedManagerSearchVMDC response = sc.SearchStaffNominatedManagers(CurrentUser, CurrentUser, appID, "", searchCritera); // Close service communication ((ICommunicationObject)sc).Close(); //Map response back to view model model.DeputyNominatedManagerSearchList = Mapper.Map <List <StaffModel> >(response.MatchList); //Adds current retrieved Site to session sessionManager.CurrentSite = model.SiteItem; sessionManager.SiteNominatedManagersSearch = model.NominatedManagerSearchList; sessionManager.SiteDeputyNominatedManagersSearch = model.DeputyNominatedManagerSearchList; sessionManager.SiteDeputyNominatedManagers = model.DeputyNominatedManagerList; return(View(model)); } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc); model.Message = message; return(View(model)); } }
public StaffNominatedManagerSearchVMDC SearchStaffNominatedManagers(string currentUser, string user, string appID, string overrideID, StaffNominatedManagerSearchVMDC staffInfo, IUnitOfWork uow, IRepository <Staff> dataRepository, IExceptionManager exceptionManager) { try { #region Parameter validation // Validate parameters if (string.IsNullOrEmpty(currentUser)) { throw new ArgumentOutOfRangeException("currentUser"); } if (string.IsNullOrEmpty(user)) { throw new ArgumentOutOfRangeException("user"); } if (string.IsNullOrEmpty(appID)) { throw new ArgumentOutOfRangeException("appID"); } if (null == staffInfo) { throw new ArgumentOutOfRangeException("staffInfo"); } if (null == dataRepository) { throw new ArgumentOutOfRangeException("dataRepository"); } if (null == uow) { throw new ArgumentOutOfRangeException("uow"); } #endregion using (uow) { // Search for staff with firstname specified ISpecification <Staff> staffFirstNameSpecification = new Specification <Staff>(x => x.FirstName.ToLower().Contains(staffInfo.FirstName.ToLower())); // Search for staff with lastname specified ISpecification <Staff> staffLastNameSpecification = new Specification <Staff>(x => x.LastName.ToLower().Contains(staffInfo.LastName.ToLower())); // Search for staff who are nominated managers ISpecification <Staff> staffNominatedManagerSpecification = new Specification <Staff>(x => x.StaffAttributes.Any(y => (y.ApplicationAttribute.AttributeName.ToUpper() == "UCB-NOMINATED-MANAGER") && (y.Application.ApplicationName.ToUpper() == "UCB"))); // Search for staff who are deputy nominated managers ISpecification <Staff> staffDeputyNominatedManagerSpecification = new Specification <Staff>(x => x.StaffAttributes.Any(y => (y.ApplicationAttribute.AttributeName.ToUpper() == "UCB-DEPUTY-NOMINATED-MANAGER") && (y.Application.ApplicationName.ToUpper() == "UCB"))); ISpecification <Staff> staffSearchSpecification = null; if (!string.IsNullOrEmpty(staffInfo.FirstName)) { staffSearchSpecification = staffFirstNameSpecification; } if (!string.IsNullOrEmpty(staffInfo.LastName)) { staffSearchSpecification = (null == staffSearchSpecification)?staffLastNameSpecification:staffSearchSpecification.And(staffLastNameSpecification); } if (staffInfo.IsNominatedManager) { staffSearchSpecification = (null == staffSearchSpecification) ? staffNominatedManagerSpecification : staffSearchSpecification.And(staffNominatedManagerSpecification); } if (staffInfo.IsDeputyNominatedManager) { staffSearchSpecification = (null == staffSearchSpecification) ? staffDeputyNominatedManagerSpecification : staffSearchSpecification.And(staffDeputyNominatedManagerSpecification); } // Set default sort expression System.Linq.Expressions.Expression <Func <Staff, Object> > sortExpression = x => x.LastName; // Get staff based on search criteria IEnumerable <Staff> staffList = dataRepository.Find(staffSearchSpecification, sortExpression); // Convert to list List <StaffDC> staffListDestination = Mapper.Map <List <StaffDC> >(staffList); staffInfo.MatchList = staffListDestination; // Return staff matching criteria return(staffInfo); } } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); return(null); } }
public StaffNominatedManagerSearchVMDC SearchStaffNominatedManagers(string currentUser, string user, string appID, string overrideID, StaffNominatedManagerSearchVMDC staffInfo) { // Create unit of work IUnitOfWork uow = new UnitOfWork(currentUser); // Create repository IRepository <Staff> dataRepository = new Repository <Staff>(uow.ObjectContext, currentUser, user, appID, overrideID); //Create ExceptionManager IExceptionManager exceptionManager = new ExceptionManager(); return(SearchStaffNominatedManagers(currentUser, user, appID, overrideID, staffInfo, uow, dataRepository, exceptionManager)); }