Exemplo n.º 1
0
        public ApiResult <CommandVM> GetOne()
        {
            //ako ima pravo pristupa
            if (false)
            {
                return(ApiResult <CommandVM> .Error(1, "Nema pravo pristupa"));
            }

            Command k = _db.Command
                        .Where(x => !x.DateExecuteStart.HasValue)
                        .OrderBy(x => x.Id)
                        .FirstOrDefault();

            if (k == null)
            {
                return(ApiResult <CommandVM> .OK(null));
            }

            k.DateExecuteStart = DateTime.Now;
            _db.SaveChanges();

            CommandVM model = new CommandVM
            {
                Id          = k.Id,
                CommandType = k.CommandType
            };

            return(ApiResult <CommandVM> .OK(model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Private method to merge in the model
        /// </summary>
        /// <returns></returns>
        private CommandVM GetUpdatedModel()
        {
            CommandVM model = new CommandVM();

            RepopulateListsFromCacheSession(model);
            model.Message = "";

            //if (SessionManager.CurrentCommand != null)
            //{
            //    model.CommandItem = SessionManager.CurrentCommand;
            //}

            //***************************************NEED WHITE LIST ---- BLACK LIST ------ TO PREVENT OVERPOSTING **************************
            bool result = TryUpdateModel(model);//This also validates and sets ModelState

            //*******************************************************************************************************************************
            //if (SessionManager.CurrentCommand != null)
            //{
            //*****************************************PREVENT OVER POSTING ATTACKS******************************************************
            //Get the values for read only fields from session
            //    MergeNewValuesWithOriginal(model.CommandItem);
            //***************************************************************************************************************************
            //}

            //SetAccessContext(model);

            //Set the context of the check based on check number
            //SetCheckContext(model);

            return(model);
        }
Exemplo n.º 3
0
        private CommandVM ConvertCommandDC(CommandVMDC returnedObject)
        {
            CommandVM model = new CommandVM();

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

            RepopulateListsFromCacheSession(model);

            return(model);
        }
Exemplo n.º 4
0
        private void RepopulateListsFromCacheSession(CommandVM model)
        {
            //*********************************
            //*PLACE HOLDER FOR SESSION LISTS *
            //*********************************


            //*********************************
            //*     POPULATE CACHED LISTS     *
            //*********************************
        }
Exemplo n.º 5
0
        private void SetFlagsFalse(CommandVM model)
        {
            model.IsDeleteConfirmed = "False";
            model.IsExitConfirmed   = "False";
            model.IsNewConfirmed    = "False";

            //Stop the binder resetting the posted values
            ModelState.Remove("IsDeleteConfirmed");
            ModelState.Remove("IsExitConfirmed");
            ModelState.Remove("IsNewConfirmed");
        }
Exemplo n.º 6
0
 private void SetAccessContext(CommandVM model)
 {
     //Decide on access context
     if (model.CommandItem.Code == Guid.Empty)
     {
         //model.AccessContext = AccessContext.Create;
     }
     else
     {
         //model.AccessContext = AccessContext.Edit;
     }
 }
Exemplo n.º 7
0
        protected CrudVMBase() : base()
        {
            ObservableCollection <CommandVM> commands = new ObservableCollection <CommandVM>
            {
                new CommandVM {
                    CommandDisplay = "Insert", IconGeometry = Application.Current.Resources["InsertIcon"] as Geometry, Message = new CommandMessage {
                        Command = CommandType.Insert
                    }
                },
                new CommandVM {
                    CommandDisplay = "Edit", IconGeometry = Application.Current.Resources["EditIcon"] as Geometry, Message = new CommandMessage {
                        Command = CommandType.Edit
                    }
                },
                new CommandVM {
                    CommandDisplay = "Delete", IconGeometry = Application.Current.Resources["DeleteIcon"] as Geometry, Message = new CommandMessage {
                        Command = CommandType.Delete
                    }
                },
                new CommandVM {
                    CommandDisplay = "Refresh", IconGeometry = Application.Current.Resources["RefreshIcon"] as Geometry, Message = new CommandMessage {
                        Command = CommandType.Refresh
                    }
                }
            };

            Commands = commands;
            RaisePropertyChanged("Commands");
            Messenger.Default.Register <CommandMessage>(this, (action) => HandleCommand(action));
            SaveCmd = new CommandVM
            {
                CommandDisplay = "Commit",
                IconGeometry   = Application.Current.Resources["SaveIcon"] as Geometry,
                Message        = new CommandMessage {
                    Command = CommandType.Commit
                }
            };
            QuitCmd = new CommandVM
            {
                CommandDisplay = "Quit",
                IconGeometry   = Application.Current.Resources["QuitIcon"] as Geometry,
                Message        = new CommandMessage {
                    Command = CommandType.Quit
                }
            };
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
0
 protected CrudVMBase()
 {
     GetData();
     Messenger.Default.Register <CommandMessage>(this, (action) => HandleCommand(action));
     Messenger.Default.Register <NavigateMessage>(this, (action) => CurrentUserControl(action));
     SaveCmd = new CommandVM
     {
         CommandDisplay = "Commit",
         IconGeometry   = Application.Current.Resources["SaveIcon"] as Geometry,
         Message        = new CommandMessage {
             Command = CommandType.Commit
         }
     };
     QuitCmd = new CommandVM
     {
         CommandDisplay = "Quit",
         IconGeometry   = Application.Current.Resources["QuitIcon"] as Geometry,
         Message        = new CommandMessage {
             Command = CommandType.Quit
         }
     };
 }
Exemplo n.º 10
0
 public void Setup()
 {
     _vm = new CommandVM();
 }
Exemplo n.º 11
0
 private void ResolveFieldCodesToFieldNamesUsingLists(CommandVM model)
 {
     var ListCache = CacheManager.ListCache;
     //TODO:
 }