Example #1
0
        public StaffDC GetNominatedManagerForSite(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow,
                                                  IRepository <Site> siteRepository, IRepository <Staff> staffRepository, 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 (string.IsNullOrEmpty(code))
                {
                    throw new ArgumentOutOfRangeException("siteCode");
                }
                if (null == siteRepository)
                {
                    throw new ArgumentOutOfRangeException("organisationRepository");
                }
                if (null == staffRepository)
                {
                    throw new ArgumentOutOfRangeException("staffRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }

                #endregion

                // Convert code to Guid
                Guid codeGuid = Guid.Parse(code);
                using (uow)
                {
                    Staff nominatedManager = staffRepository.Find(
                        new Specification <Staff>(
                            x => x.SiteStaff.Any(
                                y => y.Site.Code == codeGuid && y.Responsibility
                                == ServiceConstants.SITE_STAFF_RESPONSIBILITY_NOMINATED_MANAGER)
                            )
                        ).SingleOrDefault();

                    StaffDC returnObject = Mapper.Map <Staff, StaffDC>(nominatedManager);
                    return(returnObject);
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
        //This method is shared between create and save
        private ActionResult UpdateStaff()
        {
            // Get the updated model
            var model = GetUpdatedModel();

            // Test to see if there are any errors
            var errors = ModelState
                         .Where(x => x.Value.Errors.Count > 0)
                         .Select(x => new { x.Key, x.Value.Errors[0].ErrorMessage })
                         .ToArray();

            //Set flags false
            SetFlagsFalse(model);

            // Test to see if the model has validated correctly
            if (ModelState.IsValid)
            {
                // Create service instance
                AdminServiceClient sc = new AdminServiceClient();

                //Attempt update
                try
                {
                    // Map model to data contract
                    StaffDC StaffItem = Mapper.Map <StaffDC>(model.StaffItem);

                    StaffVMDC returnedObject = null;

                    if (null == model.StaffItem.Code || model.StaffItem.Code == Guid.Empty)
                    {
                        // Call service to create new Staff item
                        returnedObject = sc.CreateStaff(CurrentUser, CurrentUser, appID, "", StaffItem);
                    }
                    else
                    {
                        // Call service to update Staff item
                        returnedObject = sc.UpdateStaff(CurrentUser, CurrentUser, appID, "", StaffItem);
                    }

                    // Close service communication
                    sc.Close();

                    // Retrieve item returned by service
                    var createdStaff = returnedObject.StaffItem;

                    // Map data contract to model
                    model.StaffItem = Mapper.Map <StaffModel>(createdStaff);

                    //After creation some of the fields are display only so we need the resolved look up nmames
                    ResolveFieldCodesToFieldNamesUsingLists(model);

                    // Set access context to Edit mode
                    model.AccessContext = StaffAccessContext.Edit;

                    // Save version of item returned by service into session
                    SessionManager.StaffServiceVersion = model.StaffItem;
                    SessionManager.CurrentStaff        = model.StaffItem;

                    // Remove the state from the model as these are being populated by the controller and the HTML helpers are being populated with
                    // the POSTED values and not the changed ones.
                    ModelState.Clear();
                    model.Message = FixedResources.MESSAGE_UPDATE_SUCCEEDED;
                }
                catch (Exception e)
                {
                    // Handle the exception
                    string message = ExceptionManager.HandleException(e, sc);
                    model.Message = message;

                    return(View(model));
                }
            }

            return(View(model));
        }
Example #3
0
        /// <summary>
        /// Retrieve a Staff with associated lookups
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        /// <returns></returns>
        public StaffVMDC GetStaff(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <Staff> dataRepository
                                  , IRepository <Grade> gradeRepository
                                  , IExceptionManager exceptionManager, IMappingService mappingService)

        {
            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 == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    StaffDC destination = null;

                    // If code is null then just return supporting lists
                    if (!string.IsNullOrEmpty(code))
                    {
                        // Convert code to Guid
                        Guid codeGuid = Guid.Parse(code);

                        // Retrieve specific Staff
                        Staff dataEntity = dataRepository.Single(x => x.Code == codeGuid);

                        // Convert to data contract for passing through service interface
                        destination = mappingService.Map <Staff, StaffDC>(dataEntity);
                    }

                    IEnumerable <Grade> gradeList = gradeRepository.GetAll(x => new { x.Grade1 });

                    List <GradeDC> gradeDestinationList = mappingService.Map <List <GradeDC> >(gradeList);

                    // Create aggregate contract
                    StaffVMDC returnObject = new StaffVMDC();

                    returnObject.StaffItem = destination;
                    returnObject.GradeList = gradeDestinationList;

                    return(returnObject);
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
Example #4
0
        /// <summary>
        ///  Create a Staff
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public StaffVMDC CreateStaff(string currentUser, string user, string appID, string overrideID, StaffDC dc, IRepository <Staff> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService)
        {
            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 == dc)
                {
                    throw new ArgumentOutOfRangeException("dc");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    // Create a new ID for the Staff item
                    dc.Code = Guid.NewGuid();

                    // Map data contract to model
                    Staff destination = mappingService.Map <StaffDC, Staff>(dc);

                    // Add the new item
                    dataRepository.Add(destination);

                    // Commit unit of work
                    uow.Commit();

                    // Map model back to data contract to return new row id.
                    dc = mappingService.Map <Staff, StaffDC>(destination);
                }

                // Create aggregate data contract
                StaffVMDC returnObject = new StaffVMDC();

                // Add new item to aggregate
                returnObject.StaffItem = dc;

                return(returnObject);
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
Example #5
0
        /// <summary>
        /// Create a Staff
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        public StaffVMDC CreateStaff(string currentUser, string user, string appID, string overrideID, StaffDC dc)
        {
            // Create unit of work
            IUnitOfWork uow = new UnitOfWork(currentUser);

            // Create repository
            Repository <Staff> dataRepository = new Repository <Staff>(uow.ObjectContext, currentUser, user, appID, overrideID);

            //Create ExceptionManager
            IExceptionManager exceptionManager = new ExceptionManager();

            //Create MappingService
            IMappingService mappingService = new MappingService();


            // Call overload with injected objects
            return(CreateStaff(currentUser, user, appID, overrideID, dc, dataRepository, uow, exceptionManager, mappingService));
        }
Example #6
0
        /// <summary>
        /// Update a Staff
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public StaffVMDC UpdateStaff(string currentUser, string user, string appID, string overrideID, StaffDC dc, IRepository <Staff> dataRepository, IUnitOfWork uow)
        {
            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 == dc)
                {
                    throw new ArgumentOutOfRangeException("dc");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }

                #endregion

                using (uow)
                {
                    // Map data contract to model
                    Staff destination = Mapper.Map <StaffDC, Staff>(dc);

                    // Add the new item
                    dataRepository.Update(destination);

                    // Commit unit of work
                    uow.Commit();

                    dc = Mapper.Map <Staff, StaffDC>(destination);
                }

                // Create new data contract to return
                StaffVMDC returnObject = new StaffVMDC();

                // Add new item to datacontract
                returnObject.StaffItem = dc;

                // Commit unit of work
                return(returnObject);
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                ExceptionManager.ShieldException(e);

                return(null);
            }
        }
Example #7
0
        /// <summary>
        /// Update a Staff
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        public StaffVMDC UpdateStaff(string currentUser, string user, string appID, string overrideID, StaffDC dc)
        {
            // Create unit of work
            IUnitOfWork uow = new UnitOfWork(currentUser);

            // Create repository
            IRepository <Staff> dataRepository = new Repository <Staff>(uow.ObjectContext, currentUser, user, appID, overrideID);

            // Call overload with injected objects
            return(UpdateStaff(currentUser, user, appID, overrideID, dc, dataRepository, uow));
        }
Example #8
0
        /// <summary>
        /// Retrieve a Site with associated lookups
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        /// <returns></returns>
        public SiteVMDC GetSiteByOrganisationCode(string currentUser, string user, string appID, string overrideID, string organisationCode, IUnitOfWork uow, IRepository <Site> dataRepository
                                                  , IRepository <Organisation> organisationRepository, IRepository <Staff> staffRepository, 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 == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (string.IsNullOrEmpty(organisationCode))
                {
                    throw new ArgumentOutOfRangeException("organisationCode");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("organisationRepository");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("staffRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }

                #endregion

                using (uow)
                {
                    SiteDC         destination = null;
                    StaffDC        currentNominatedManagerDestination        = null;
                    List <StaffDC> currentDeputyNominatedManagersDestination = null;

                    // Convert code to Guid
                    Guid organisationCodeGuid = Guid.Parse(organisationCode);

                    // Retrieve specific Site
                    Site dataEntity = dataRepository.Find(x => x.OrganisationCode == organisationCodeGuid).SingleOrDefault();

                    // See if Site has already been created
                    if (null != dataEntity)
                    {
                        // Convert to data contract for passing through service interface
                        destination = Mapper.Map <Site, SiteDC>(dataEntity);

                        Guid siteCodeGuid = dataEntity.Code;

                        // Get nominated manager for this Site
                        ISpecification <Staff> currentNominatedManagerSpecification = new Specification <Staff>(
                            x => x.SiteStaff.Any(
                                y => y.SiteCode == siteCodeGuid && y.Responsibility.ToLower() ==
                                ServiceConstants.SITE_STAFF_RESPONSIBILITY_NOMINATED_MANAGER.ToLower()
                                )
                            );

                        Staff currentNominatedManager = staffRepository.Single(currentNominatedManagerSpecification);
                        currentNominatedManagerDestination = Mapper.Map <StaffDC>(currentNominatedManager);

                        // Get deputy nominated managers for this Site
                        ISpecification <Staff> currentDeputyNominatedManagerSpecification = new Specification <Staff>(
                            x => x.SiteStaff.Any(
                                y => y.SiteCode == siteCodeGuid && y.Responsibility.ToLower() ==
                                ServiceConstants.SITE_STAFF_RESPONSIBILITY_DEPUTY_NOMINATED_MANAGER.ToLower()
                                )
                            );

                        IEnumerable <Staff> currentDeputyNominatedManagerList = staffRepository.Find(currentDeputyNominatedManagerSpecification);
                        currentDeputyNominatedManagersDestination = Mapper.Map <List <StaffDC> >(currentDeputyNominatedManagerList);
                    }
                    else
                    // If site does not exist then create Site object and provide default Site name same a Organisation name
                    {
                        // Get site organisations
                        ISpecification <Organisation> siteOrgansiationSpecification = new Specification <Organisation>(x => x.Code == organisationCodeGuid);
                        Organisation siteOrganisation = organisationRepository.Single(siteOrgansiationSpecification);

                        destination = new SiteDC();
                        destination.OrganisationCode = siteOrganisation.Code;
                        destination.IsActive         = true;

                        // Provide default Site name, same as Organisation Name
                        destination.SiteName = siteOrganisation.Name;
                    }

                    // Create aggregate contract
                    SiteVMDC returnObject = new SiteVMDC();

                    returnObject.SiteItem = destination;

                    // Set Nominated Manager
                    if (null != currentNominatedManagerDestination)
                    {
                        returnObject.NominatedManagerCode       = currentNominatedManagerDestination.Code.ToString();
                        returnObject.NominatedManagerSearchList = new List <StaffDC>();
                        returnObject.NominatedManagerSearchList.Add(currentNominatedManagerDestination);
                    }
                    // Set Deputy Nominated Managers
                    returnObject.DeputyNominatedManagerList = currentDeputyNominatedManagersDestination;

                    return(returnObject);
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
Example #9
0
        public ActionResult SaveStaffAdmin(Guid?staffCode, FormCollection form)
        {
            var model = GetUpdatedModel();

            //Set flags false
            SetFlagsFalse(model);
            //boolean variable that is set to false by default. It is used to check if an application requires a default application.
            bool isDefaultOrgRequiredApplication = false;
            var  defaultradio = Request.Form["defaultradio"];

            foreach (var item in model.StaffApplicationAttributeList)
            {
                //ApplicationAttrbiute contains rows to indicate applications that require a default organisation set for a application.
                if (item.ApplicationAttributeItem.AttributeName == "IsDefaultOrgRequired")
                {
                    isDefaultOrgRequiredApplication = true;
                }
            }

            //Below code added for checking to see if user has chosen a default appllication based on whether it is required.
            if (isDefaultOrgRequiredApplication == true)
            {
                if (defaultradio == null)
                {
                    if (model.StaffOrganisationList.Count() > 1)
                    {
                        //if application organisation list contains more than one value, show user error message and do not save.
                        model.Message = "This application requires a default staff organisation, please select a default.";
                        return(View(model));
                    }
                    else if (model.StaffOrganisationList.Count() == 1)
                    {
                        //if only one application organisation exists, then set that as a default organistion.
                        model.StaffOrganisationList[0].IsDefault = true;
                    }
                }
            }

            //Save the changes by calling the service

            var changeSet = EstablishAdminChangeSet(model);

            StaffDC staffItem = Mapper.Map <StaffDC>(model.StaffItem);

            var sc = new AdminServiceClient();

            //IF SelectedApplicationCode is not null
            if (model.SelectedApplicationCode != null)
            {
                //Save the changeset
                try
                {
                    var returnedObject = sc.UpdateStaffApplicationAdministration(User.Identity.Name, User.Identity.Name, "Framework", "", model.SelectedApplicationCode.Value, staffItem, changeSet);
                    MergeReturnedObjectToModel(model, returnedObject);
                    model.Message = FixedResources.MESSAGE_UPDATE_SUCCEEDED;
                }
                catch (Exception e)
                {
                    string message = ExceptionManager.HandleException(e, sc);
                    model.Message = message;
                    //model.Message = FixedResources.MESSAGE_UPDATE_FAILED;
                    return(View(model));
                }
            }
            else //model.SelectedApplicationCode IS null
            {
                model.Message = FixedResources.MESSAGE_UPDATE_NOCHANGE;
            }

            DetermineIsDirty(model);

            return(View(model));
        }