Esempio n. 1
0
        /// <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 CommandVMDC GetCommand(string userName, string currentUserName, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <Command> dataRepository
                                      )

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

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

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



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

                    message.CommandItem = destination;

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

                return(null);
            }
        }
Esempio n. 2
0
        private CommandVM ConvertCommandDC(CommandVMDC returnedObject)
        {
            CommandVM model = new CommandVM();

            model.CommandItem = Mapper.Map <CommandDC, CommandModel>(returnedObject.CommandItem);

            RepopulateListsFromCacheSession(model);

            return(model);
        }
Esempio n. 3
0
        //This method is shared between create and save
        private ActionResult UpdateCommand()
        {
            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();
                    CommandDC          CommandToCreate = Mapper.Map <CommandDC>(model.CommandItem);
                    CommandVMDC        returnedObject  = null;//sc.SaveCommand(SessionManager.UserID, SessionManager.UserID, "SecurityMonitoring", "", CommandToCreate);
                    var createdCommand = returnedObject.CommandItem;

                    model.CommandItem = Mapper.Map <CommandModel>(createdCommand);

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

                    //model.AccessContext = CommandAccessContext.Edit;

                    //SessionManager.CommandDBVersion = model.CommandItem;
                    //SessionManager.CurrentCommand = model.CommandItem;

                    // 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));
        }
Esempio n. 4
0
        // GET: /Command/Edit?code=
        public ActionResult Edit(string code)
        {
            CommandVM model = new CommandVM();

            //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.CommandItem = new CommandModel();
            }
            //if we have been passed a code then assume we are in edit situation and we need to retreive from the database.
            else
            {
                try
                {
                    AdminServiceClient sc             = new AdminServiceClient();
                    CommandVMDC        returnedObject = null;//sc.GetSecurityCheckAndLookUps(SessionManager.UserID, SessionManager.UserID, "SecurityMonitoring", "", false, code);

                    //Get view model from database
                    model = ConvertCommandDC(returnedObject);

                    ResolveFieldCodesToFieldNamesUsingLists(model);

                    //Store the DB version of the check.
                    //SessionManager.CommandDBVersion = model.CommandItem;
                }
                catch (Exception e)
                {
                    SetAccessContext(model);
                    model.Message = Resources.MESSAGE_RETREIVAL_FAILED;
                    return(View(model));
                }
            }

            //Adds current retreived Command to session
            //SessionManager.CurrentCommand = model.CommandItem;
            //SetAccessContext(model);

            return(View(model));
        }
Esempio n. 5
0
 private void AddListsToSession(CommandVMDC returnedObject)
 {
     //*********************************
     //*PLACE HOLDER FOR SESSION LISTS *
     //*********************************
 }