/// <summary>
        ///
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="currentUserName"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        /// <returns></returns>
        public StaffAttributeVMDC GetStaffAttribute(string userName, string currentUserName, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <StaffAttribute> dataRepository
                                                    , IRepository <Staff> staffRepository
                                                    , IRepository <Application> applicationRepository
                                                    , IRepository <ApplicationAttribute> applicationAttributeRepository
                                                    )

        {
            try
            {
                using (uow)
                {
                    // Convert code to Guid
                    Guid codeGuid = Guid.Parse(code);

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

                    // Convert to data contract for passing through service interface
                    StaffAttributeDC destination = Mapper.Map <StaffAttribute, StaffAttributeDC>(dataEntity);

                    IEnumerable <Staff>                staffList                = staffRepository.GetAll();
                    IEnumerable <Application>          applicationList          = applicationRepository.GetAll();
                    IEnumerable <ApplicationAttribute> applicationAttributeList = applicationAttributeRepository.GetAll();

                    List <StaffDC>                staffDestinationList                = Mapper.Map <List <StaffDC> >(staffList);
                    List <ApplicationDC>          applicationDestinationList          = Mapper.Map <List <ApplicationDC> >(applicationList);
                    List <ApplicationAttributeDC> applicationAttributeDestinationList = Mapper.Map <List <ApplicationAttributeDC> >(applicationAttributeList);

                    // Create aggregate contract
                    StaffAttributeVMDC message = new StaffAttributeVMDC();

                    message.StaffAttributeItem       = destination;
                    message.StaffList                = staffDestinationList;
                    message.ApplicationList          = applicationDestinationList;
                    message.ApplicationAttributeList = applicationAttributeDestinationList;

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

                return(null);
            }
        }
예제 #2
0
        //This method is shared between create and save
        private ActionResult UpdateStaffAttribute()
        {
            var model = GetUpdatedModel();

            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);
            if (ModelState.IsValid)
            {
                //Attempt update
                try
                {
                    AdminServiceClient sc = new AdminServiceClient();
                    StaffAttributeDC   StaffAttributeToCreate = Mapper.Map <StaffAttributeDC>(model.StaffAttributeItem);
                    StaffAttributeVMDC returnedObject         = null;//sc.SaveStaffAttribute(SessionManager.UserID, SessionManager.UserID, "SecurityMonitoring", "", StaffAttributeToCreate);
                    var createdStaffAttribute = returnedObject.StaffAttributeItem;

                    model.StaffAttributeItem = Mapper.Map <StaffAttributeModel>(createdStaffAttribute);

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

                    //model.AccessContext = StaffAttributeAccessContext.Edit;

                    //SessionManager.StaffAttributeDBVersion = model.StaffAttributeItem;
                    //SessionManager.CurrentStaffAttribute = model.StaffAttributeItem;

                    // 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 = Resources.MESSAGE_UPDATE_SUCCEEDED;
                }
                catch (Exception e)
                {
                    model.Message = Resources.MESSAGE_UPDATE_FAILED;
                    return(View(model));
                }
            }

            return(View(model));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="currentUserName"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public void CreateStaffAttribute(string userName, string currentUserName, string appID, string overrideID, StaffAttributeDC dc, IRepository <StaffAttribute> dataRepository, IUnitOfWork uow)
        {
            try
            {
                using (uow)
                {
                    StaffAttribute destination = Mapper.Map <StaffAttributeDC, StaffAttribute>(dc);

                    dataRepository.Add(destination);

                    uow.Commit();
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                ExceptionManager.ShieldException(e);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="currentUserName"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        public void CreateStaffAttribute(string userName, string currentUserName, string appID, string overrideID, StaffAttributeDC dc)
        {
            IUnitOfWork uow = new UnitOfWork();

            Repository <StaffAttribute> dataRepository = new Repository <StaffAttribute>(uow.ObjectContext, userName, currentUserName, appID, overrideID);

            CreateStaffAttribute(userName, currentUserName, appID, overrideID, dc, dataRepository, uow);
        }