/// <summary>
 /// Closes the existing connection to the service
 /// </summary>
 public static void CloseClient()
 {
     if (clientInstance != null)
     {
         clientInstance.Close();
     }
 }
Exemplo n.º 2
0
        public ActionResult Edit()
        {
            // Retrieve ID from session
            string code = SessionManager.OrganisationTypeCode;

            OrganisationTypeVM model = new OrganisationTypeVM();

            // Not from staff or error
            if (String.IsNullOrEmpty(code))
            {
                //If session has lists then use them
                RepopulateListsFromCacheSession(model);

                //Assume we are in create mode as no code passed
                model.OrganisationTypeItem = new OrganisationTypeModel()
                {
                    IsActive = true
                };
            }
            //if we have been passed a code then assume we are in edit situation and we need to retrieve from the database.
            else
            {
                // Create service instance
                AdminServiceClient sc = new AdminServiceClient();

                try
                {
                    // Call service to get OrganisationType item and any associated lookups
                    OrganisationTypeVMDC returnedObject = sc.GetOrganisationType(CurrentUser, CurrentUser, appID, "", code);

                    // Close service communication
                    sc.Close();

                    //Get view model from service
                    model = ConvertOrganisationTypeDC(returnedObject);

                    ResolveFieldCodesToFieldNamesUsingLists(model);

                    //Store the service version
                    SessionManager.OrganisationTypeServiceVersion = model.OrganisationTypeItem;
                }
                catch (Exception e)
                {
                    // Handle the exception
                    string message = ExceptionManager.HandleException(e, sc);
                    model.Message = message;

                    return(View(model));
                }
            }

            //Adds current retrieved OrganisationType to session
            SessionManager.CurrentOrganisationType = model.OrganisationTypeItem;
            SetAccessContext(model);

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult DeleteCommands(FormCollection collection)
        {
            var model = GetUpdatedModel();

            if (model.IsDeleteConfirmed == "True")
            {
                //Set flags false
                SetFlagsFalse(model);

                model.IsDeleteConfirmed = "False";

                // Create service instance
                AdminServiceClient sc = new AdminServiceClient();

                try
                {
                    // Call service to delete the item
                    sc.DeleteCommands(CurrentUser, CurrentUser, appID, "", model.CommandsItem.Code.ToString(), model.CommandsItem.RowIdentifier.ToString());

                    // Close service communication
                    sc.Close();

                    // Remove the current values from session
                    SessionManager.CurrentCommands        = null;
                    SessionManager.CommandsServiceVersion = null;

                    // Redirect to the search screen
                    return(RedirectToAction("Search", "Commands"));
                }
                catch (Exception e)
                {
                    // Handle the exception
                    string message = ExceptionManager.HandleException(e, sc);
                    model.Message = message;

                    return(View(model));
                }
            }
            else
            {
                //Set flags false
                SetFlagsFalse(model);
                model.Message           = FixedResources.MESSAGE_DELETECONFIRMATION;
                model.IsDeleteConfirmed = "True";
            }

            return(View(model));
        }
        public ActionResult Search(int page = 1)
        {
            // Create service instance
            AdminServiceClient sc = new AdminServiceClient();

            // Create model
            StaffSearchVM model = new StaffSearchVM();

            try
            {
                #region Setup search citeria

                //Create search criteria data conatract
                StaffSearchCriteriaDC searchCriteriaDC = Mapper.Map <StaffSearchCriteriaDC>(model.SearchCriteria);

                #endregion

                // Call service
                StaffSearchVMDC response = sc.SearchStaff(CurrentUser, CurrentUser, appID, "", searchCriteriaDC, page, PageSize, true);

                // Close service communication
                sc.Close();

                //Map response back to view model
                model.MatchList = Mapper.Map <IEnumerable <StaffSearchMatchDC>, List <StaffSearchMatchModel> >(response.MatchList);

                // Set paging values
                model.TotalRows  = response.RecordCount;
                model.PageSize   = SessionManager.PageSize;
                model.PageNumber = page;

                // Store the page number we were on
                SessionManager.StaffPageNumber = model.PageNumber;

                return(View(model));
            }
            catch (Exception e)
            {
                // Handle the exception
                string message = ExceptionManager.HandleException(e, sc);
                model.Message = message;

                return(View(model));
            }
        }
        public ActionResult SearchPost(StaffSearchVM model, int page = 1)
        {
            // Create service instance
            AdminServiceClient sc = new AdminServiceClient();

            #region Setup search citeria

            //Repopulate search criteria if already entered
            if (null == model.SearchCriteria && SessionManager.StaffSearchCritera != null)
            {
                model.SearchCriteria = SessionManager.StaffSearchCritera;
            }

            //Save search criteria to session
            SessionManager.StaffSearchCritera = model.SearchCriteria;

            //Create search criteria data conatract
            StaffSearchCriteriaDC searchCriteriaDC = Mapper.Map <StaffSearchCriteriaDC>(model.SearchCriteria);

            #endregion

            // Call service
            StaffSearchVMDC response = sc.SearchStaff(CurrentUser, CurrentUser, appID, "", searchCriteriaDC, page, PageSize, true);

            // Close service communication
            sc.Close();

            //Map response back to view model
            model.MatchList = Mapper.Map <IEnumerable <StaffSearchMatchDC>, List <StaffSearchMatchModel> >(response.MatchList);

            // Set paging values
            model.TotalRows  = response.RecordCount;
            model.PageSize   = SessionManager.PageSize;
            model.PageNumber = page;

            // Store the page number we were on
            SessionManager.StaffPageNumber = model.PageNumber;

            return(View(model));
        }
        public ActionResult Search(int page = 1)
        {
            // Create service instance
            AdminServiceClient sc = new AdminServiceClient();

            // Create model
            StaffOfficesSearchVM model = new StaffOfficesSearchVM();

            try
            {
                StaffOfficesSearchVMDC response = sc.SearchStaffOffices(CurrentUser, CurrentUser, appID, "", null, page, PageSize);

                // Close service communication
                sc.Close();

                //Map response back to view model
                model.MatchList = Mapper.Map <IEnumerable <StaffOfficesSearchMatchDC>, List <StaffOfficesSearchMatchModel> >(response.MatchList);

                // Set paging values
                model.TotalRows  = response.RecordCount;
                model.PageSize   = SessionManager.PageSize;
                model.PageNumber = page;

                // Store the page number we were on
                SessionManager.StaffOfficesPageNumber = model.PageNumber;

                return(View(model));
            }
            catch (Exception e)
            {
                // Handle the exception
                string message = ExceptionManager.HandleException(e, sc);
                model.Message = message;

                return(View(model));
            }
        }
        //This method is shared between create and save
        private ActionResult UpdateStaffOffices()
        {
            // 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
                    StaffOfficesDC StaffOfficesItem = Mapper.Map <StaffOfficesDC>(model.StaffOfficesItem);

                    StaffOfficesVMDC returnedObject = null;

                    if (null == model.StaffOfficesItem.Code || model.StaffOfficesItem.Code == Guid.Empty)
                    {
                        // Call service to create new StaffOffices item
                        returnedObject = sc.CreateStaffOffices(CurrentUser, CurrentUser, appID, "", StaffOfficesItem);
                    }
                    else
                    {
                        // Call service to update StaffOffices item
                        returnedObject = sc.UpdateStaffOffices(CurrentUser, CurrentUser, appID, "", StaffOfficesItem);
                    }

                    // Close service communication
                    sc.Close();

                    // Retrieve item returned by service
                    var createdStaffOffices = returnedObject.StaffOfficesItem;

                    // Map data contract to model
                    model.StaffOfficesItem = Mapper.Map <StaffOfficesModel>(createdStaffOffices);

                    //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 = StaffOfficesAccessContext.Edit;

                    // Save version of item returned by service into session
                    SessionManager.StaffOfficesServiceVersion = model.StaffOfficesItem;
                    SessionManager.CurrentStaffOffices        = model.StaffOfficesItem;

                    // 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));
        }
Exemplo n.º 8
0
        //This method is shared between create and save
        private ActionResult UpdateOrganisation()
        {
            // Get the updated model
            var model = GetUpdatedModelOrg();

            // 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
                {
                    //FindParentOrganisation
                    var SelectedOrganisationTypeCode = model.OrganisationItem.OrganisationTypeCode;
                    var SelectedOrganisationTypeParentLevelNumber = model.AllTypesForApplication.Single(x => x.Code == SelectedOrganisationTypeCode).LevelNumber - 2;
                    //OrganisationByTypeVM ParentOrgsList = SessionManager.AllOrganisationsForApplicationByTypesList[SelectedOrganisationTypeParentLevelNumber];
                    //var ParentOrganisation = ParentOrgsList.OrganisationList.Single(x => x.Code == model.ParentOrganisationCode);


                    // Map model to data contract
                    OrganisationDC OrganisationItem = Mapper.Map <OrganisationDC>(model.OrganisationItem);

                    ApplicationOrganisationAdminVMDC returnedObject = null;

                    if (null == model.OrganisationItem.Code || model.OrganisationItem.Code == Guid.Empty)
                    {
                        // Call service to create new Organisation item
                        returnedObject = sc.CreateOrganisationForApplication(CurrentUser, CurrentUser, appID, "", OrganisationItem, model.ParentOrganisationCode, Guid.Parse(SessionManager.ApplicationCode));
                    }
                    else
                    {
                        // Call service to update Organisation item
                        returnedObject = sc.UpdateOrganisationForApplication(CurrentUser, CurrentUser, appID, "", OrganisationItem, model.ParentOrganisationCode, Guid.Parse(SessionManager.ApplicationCode));
                    }

                    // Close service communication
                    sc.Close();

                    //not saved because organisation already existed
                    if (!string.IsNullOrEmpty(returnedObject.Message))
                    {
                        if (returnedObject.Message.Contains("Update failed"))
                        {
                            // Set access context to Edit mode
                            model.AccessContext = ApplicationOrganisationAccessContext.Edit;
                            model.Message       = FixedResources.MESSAGE_UPDATEFAILED_DUE_TO_ORGANISATIONALREADY_EXISTS;
                        }
                        else
                        {
                            // Set access context to Create mode
                            model.AccessContext = ApplicationOrganisationAccessContext.Create;
                            model.Message       = FixedResources.MESSAGE_CREATEFAILED_DUE_TO_ORGANISATIONALREADY_EXISTS;
                        }
                    }

                    else
                    {
                        //Get view model from service
                        model = ConvertApplicationOrganisationDC(returnedObject);

                        SessionManager.RootOrganisation               = model.RootNodeOrganisation;
                        SessionManager.OrganisationServiceVersion     = model.OrganisationItem.Clone();
                        SessionManager.MaximumHopsToChildOrganisation = model.MaximumHopsToChildOrganisation;
                        // Save version of item returned by service into session
                        SessionManager.OrganisationServiceVersion = model.OrganisationItem.Clone();
                        SessionManager.CurrentOrganisation        = model.OrganisationItem;


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

                        ResolveFieldCodesToFieldNamesUsingLists(model);
                        AddListsToSession(model);
                        //Store the service version
                        SessionManager.OrganisationServiceVersion = model.OrganisationItem;
                        // 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));
        }