/// <summary>
        /// Constructor for New Form
        /// </summary>
        public NewForm()
        {
            InitializeComponent();

            viewModel = App.MainViewModel.CreateItemViewModelInstance;
            if (!viewModel.IsInitialized)
            {
                viewModel.InitializationCompleted += new EventHandler<InitializationCompletedEventArgs>(OnViewModelInitialization);
                viewModel.Initialize();
            }
            else
            {
                this.DataContext = viewModel;
            }
        }
Example #2
0
 public NewItemPage()
 {
     InitializeComponent();
     BindingContext = new NewItemViewModel();
 }
Example #3
0
 public void TestInitialize()
 {
     // Would be good to implement some dependency injection with these view models.
     viewModel = new NewItemViewModel();
 }
Example #4
0
 public NewItemPage(string itemid)
 {
     InitializeComponent();
     BindingContext = new NewItemViewModel(itemid);
 }
Example #5
0
 public NewItemPage(Item existing_item)
 {
     InitializeComponent();
     BindingContext = NewItemViewModel = new NewItemViewModel(existing_item);
     EditMode       = true;
 }
 public ActionResult NewItem(NewItemViewModel nivm)
 {
     if (Session["User"] == null)
     {
         return RedirectToAction("LoginPage", "Application");
     }
     else if (!Session["Elevation"].Equals("Administrator"))
     {
         return RedirectToAction("LoggedInProfile");
     }
     else
     {
         if (db.Items.Where(x => x.name == nivm.name).Count() > 0)
         {
             this.ModelState.AddModelError("name", "Error: Duplicate Name");
         }
         if (ModelState.IsValid) // checks required in model. does server validation
         {
             Item i = new Item();
             i.name = nivm.name;
             i.description = nivm.description;
             i.price = nivm.price;
             UploadImage(nivm.image, nivm.name + ".png");
             db.Items.Add(i);
             db.SaveChanges();
             return RedirectToAction("Store", "Application");
         }
         else
         {
             return RedirectToAction("Store", "Application");
         }
     }
 }
Example #7
0
 public ViewModelLocator()
 {
     ItemsViewModel      = new ItemsViewModel(new LocalTodoDataStore(), new UwpNavigationService(this));
     ItemDetailViewModel = new ItemDetailViewModel(new UwpNavigationService(this), new LocalTodoDataStore(), new LocalPomodoroDataStore());
     NewItemViewModel    = new NewItemViewModel(new UwpNavigationService(this), new LocalTodoDataStore());
 }
Example #8
0
 public NewItemPage(Item.status status)
 {
     InitializeComponent();
     BindingContext = NewItemViewModel = new NewItemViewModel(status);
 }
        public ActionResult Refresh(int?baseType, int?type, int?attribute1, int?attribute2)
        {
            var baseTypes = _context.BaseTypes.ToList();

            var itemsList = _context.ItemsDB.ToList();

            int baseTypeId, typeId, attribute1Id, attribute2Id;

            baseTypeId   = baseType != null ? baseType.Value : -1;
            typeId       = type != null ? type.Value : -1;
            attribute1Id = attribute1 != null ? attribute1.Value : -1;
            attribute2Id = attribute2 != null ? attribute2.Value : -1;

            bool isBaseTypeInDb = baseTypes.Any(i => i.Id == baseTypeId);

            bool isTypeIdInDb = baseTypes
                                .SelectMany(i => i.Types)
                                .Any(i => i.Id == typeId);

            var types = (List <ItemType>)null;

            if (isTypeIdInDb)
            {
                if (isBaseTypeInDb)
                {
                    types = baseTypes
                            .Where(i => i.Id == baseTypeId)
                            .SelectMany(i => i.Types)
                            .ToList();
                }
                else
                {
                    types = baseTypes
                            .SelectMany(i => i.Types)
                            .ToList();
                }
            }
            else
            {
                types = baseTypes
                        .SelectMany(i => i.Types)
                        .Where(i => i.BaseTypeId == baseTypeId)
                        .ToList();

                if (types.Count() == 0)
                {
                    types = baseTypes
                            .SelectMany(i => i.Types)
                            .ToList();
                }
            }

            bool isBaseTypeArmour = baseTypes.SelectMany(i => i.Attributes).Any(i => i.BaseTypeId == baseTypeId);
            bool isTypeArmour     = baseTypes.Where(i => i.Name == "Armour").SelectMany(i => i.Types).Any(i => i.Id == typeId);

            var attributes = (List <ItemAttribute>)null;
            var items      = (List <ItemDB>)null;

            // This part of code applies only to items with attributes (armour and it's types)
            if (isBaseTypeArmour || isTypeArmour || !isBaseTypeInDb && !isTypeIdInDb)
            {
                bool isAttr1InDb = baseTypes
                                   .SelectMany(i => i.Attributes)
                                   .Any(i => i.Id == attribute1Id);

                bool isAttr2InDb = baseTypes
                                   .SelectMany(i => i.Attributes)
                                   .Any(i => i.Id == attribute2Id);

                attributes = baseTypes
                             .SelectMany(i => i.Attributes)
                             .ToList();

                if (isAttr1InDb && !isAttr2InDb)
                {
                    var firstFilter = attributes
                                      .Where(i => i.Id == attribute1Id)
                                      .SelectMany(i => i.Items)
                                      .ToList();

                    var secondFilter = attributes
                                       .Where(i => i.Id != attribute1Id)
                                       .SelectMany(i => i.Items)
                                       .ToList();

                    items = new List <ItemDB>();
                    foreach (var item in firstFilter)
                    {
                        bool match = secondFilter.Any(i => i.Id == item.Id);
                        if (!match)
                        {
                            items.Add(item);
                        }
                    }
                }

                else if (!isAttr1InDb && isAttr2InDb)
                {
                    var firstFilter = attributes
                                      .Where(i => i.Id == attribute2Id)
                                      .SelectMany(i => i.Items)
                                      .ToList();

                    var secondFilter = attributes
                                       .Where(i => i.Id != attribute2Id)
                                       .SelectMany(i => i.Items)
                                       .ToList();

                    items = new List <ItemDB>();
                    foreach (var item in firstFilter)
                    {
                        bool match = secondFilter.Any(i => i.Id == item.Id);
                        if (!match)
                        {
                            items.Add(item);
                        }
                    }
                }

                else if (isAttr1InDb && isAttr2InDb)
                {
                    if (attribute1Id != attribute2Id)
                    {
                        var firstFilter = attributes
                                          .Where(i => i.Id == attribute1Id)
                                          .SelectMany(i => i.Items)
                                          .ToList();

                        var secondFilter = attributes
                                           .Where(i => i.Id == attribute2Id)
                                           .SelectMany(i => i.Items)
                                           .ToList();

                        items = firstFilter
                                .Join(secondFilter,
                                      a => a.Id,
                                      b => b.Id,
                                      (a, b) => new ItemDB()
                        {
                            Attributes = b.Attributes,
                            BaseType   = b.BaseType,
                            BaseTypeId = b.BaseTypeId,
                            Id         = b.Id,
                            Level      = b.Level,
                            Name       = b.Name,
                            Type       = b.Type,
                            TypeId     = b.TypeId
                        })
                                .ToList();
                    }
                    else
                    {
                        var firstFilter = attributes
                                          .Where(i => i.Id == attribute1Id)
                                          .SelectMany(i => i.Items)
                                          .ToList();

                        var secondFilter = attributes
                                           .Where(i => i.Id != attribute2Id)
                                           .SelectMany(i => i.Items)
                                           .ToList();

                        items = new List <ItemDB>();
                        foreach (var item in firstFilter)
                        {
                            bool match = secondFilter.Any(i => i.Id == item.Id);
                            if (!match)
                            {
                                items.Add(item);
                            }
                        }
                    }
                }

                if (isTypeIdInDb && items != null)
                {
                    items = items.Where(i => i.TypeId == typeId).ToList();
                }
                else if (isBaseTypeInDb && items != null)
                {
                    items = items.Where(i => i.BaseTypeId == baseTypeId).ToList();
                }
                else if (isTypeIdInDb)
                {
                    items = itemsList
                            .Where(i => i.TypeId == typeId)
                            .Select(i => i)
                            .ToList();
                }
                else if (isBaseTypeInDb)
                {
                    items = itemsList
                            .Where(i => i.BaseTypeId == baseTypeId)
                            .Select(i => i)
                            .ToList();
                }
                else if (attributes.Any(i => i.Id == attribute1Id) || attributes.Any(i => i.Id == attribute2Id))
                {
                }
                else
                {
                    items = itemsList;
                }
            }

            // If item doesn't have attribute.
            else
            {
                if (isTypeIdInDb)
                {
                    items = itemsList
                            .Where(i => i.TypeId == typeId)
                            .Select(i => i)
                            .ToList();
                }
                else if (isBaseTypeInDb)
                {
                    items = itemsList
                            .Where(i => i.BaseTypeId == baseTypeId)
                            .Select(i => i)
                            .ToList();
                }
                else
                {
                    items = itemsList;
                }
            }

            var viewModel = new NewItemViewModel()
            {
                BaseTypes  = baseTypes,
                Types      = types,
                Attributes = attributes,
                Items      = items,
            };

            return(PartialView("_RefreshPartial", viewModel));
        }
Example #10
0
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind,
                               object[] customParams)
        {
            string itemName = replacementsDictionary["$safeitemname$"];

            ThreadHelper.ThrowIfNotOnUIThread();

            if (automationObject is DTE dte)
            {
                object activeProjects      = dte.ActiveSolutionProjects;
                Array  activeProjectsArray = (Array)activeProjects;
                if (activeProjectsArray.Length > 0)
                {
                    Project project = (Project)activeProjectsArray.GetValue(0);
                    if (project != null)
                    {
                        IEnumerable <string> validProjectTypes = Enumerable.Empty <string>();
                        string itemType = string.Empty;
                        GetWizardDataFromTemplate();

                        string projectDirectory = Path.GetDirectoryName(project.FullName);
                        ProjectInformationCommandResult projectInformation = _plcncliCommunication.ExecuteCommand(Resources.Command_get_project_information, null,
                                                                                                                  typeof(ProjectInformationCommandResult),
                                                                                                                  Resources.Option_get_project_information_no_include_detection,
                                                                                                                  Resources.Option_get_project_information_project, $"\"{projectDirectory}\"") as ProjectInformationCommandResult;
                        string projecttype = projectInformation.Type;

                        if (projecttype == null || !validProjectTypes.Contains(projecttype))
                        {
                            MessageBox.Show(
                                $"This template is not available for the selected project. The template is available for the project types" +
                                $"{validProjectTypes.Aggregate(string.Empty, (s1, s2) => s1 + $"\n'{s2}'")}\nbut the selected project is of type\n'{projecttype}'.",
                                "Template not available for project type",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                            throw new WizardBackoutException();
                        }

                        NewItemModel      model     = new NewItemModel(_plcncliCommunication, projectDirectory, itemType);
                        NewItemViewModel  viewModel = new NewItemViewModel(model);
                        NewItemDialogView view      = new NewItemDialogView(viewModel);

                        bool?result = view.ShowModal();
                        if (result != null && result == true)
                        {
                            try
                            {
                                if (itemType.Equals(Resources.ItemType_program))
                                {
                                    _plcncliCommunication.ExecuteCommand(Resources.Command_new_program, null, null,
                                                                         Resources.Option_new_program_project, $"\"{projectDirectory}\"",
                                                                         Resources.Option_new_program_name, itemName,
                                                                         Resources.Option_new_program_component, model.SelectedComponent,
                                                                         Resources.Option_new_program_namespace, model.SelectedNamespace);
                                }
                                else if (itemType.Equals(Resources.ItemType_component))
                                {
                                    string command = Resources.Command_new_component;
                                    if (projecttype.Equals(Resources.ProjectType_ACF))
                                    {
                                        command = Resources.Command_new_acfcomponent;
                                    }
                                    _plcncliCommunication.ExecuteCommand(command, null, null,
                                                                         Resources.Option_new_component_project, $"\"{projectDirectory}\"",
                                                                         Resources.Option_new_component_name, itemName,
                                                                         Resources.Option_new_component_namespace, model.SelectedNamespace);
                                }

                                string[] itemFiles = Directory.GetFiles(Path.Combine(projectDirectory, "src"), $"{itemName}.*pp");
                                foreach (string itemFile in itemFiles)
                                {
                                    project.ProjectItems.AddFromFile(itemFile);
                                }

                                _plcncliCommunication.ExecuteCommand(Resources.Command_generate_code, null, null,
                                                                     Resources.Option_generate_code_project, $"\"{projectDirectory}\"");
                            }catch (PlcncliException e)
                            {
                                MessageBox.Show(e.Message, "Error occured", MessageBoxButton.OK, MessageBoxImage.Error);
                                throw new WizardBackoutException();
                            }
                        }


                        void GetWizardDataFromTemplate()
                        {
                            string wizardData = replacementsDictionary["$wizarddata$"];

                            XDocument  document = XDocument.Parse(wizardData);
                            XNamespace nspace   = document.Root.GetDefaultNamespace();

                            validProjectTypes = document.Element(nspace + "Data").Element(nspace + "ValidProjectTypes")
                                                .Descendants(nspace + "Type").Select(e => e.Value);

                            itemType =
                                document.Element(nspace + "Data").Element(nspace + "ItemType").Value;
                        }
                    }
                }
            }
        }
Example #11
0
 void RefreshCategory(NewItemViewModel obj, Category category)
 {
     categoryPicker.SelectedItem = category;
 }
Example #12
0
 public NewItemPage(List <ItemModel> itemsList)
 {
     InitializeComponent();
     BindingContext = new NewItemViewModel(itemsList);
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _vm = new NewItemViewModel(new IosNavigation(this), new LocalTodoDataStore());
        }
Example #14
0
 public NewItemPage()
 {
     InitializeComponent();
     // This is where the view model is bound to this view.
     BindingContext = new NewItemViewModel();
 }
Example #15
0
 public NewItemPage()
 {
     InitializeComponent();
     SaveSum.Text   = NewItemViewModel.sum.ToString();
     BindingContext = new NewItemViewModel();
 }