示例#1
0
        //******BELOW ARE ALL OF THE HELPER METHODS******
        private List <ItemTagsLocation> FindMyInventory(RoboDexer loggedInRoboDexer)
        {
            var allItems = _repo.Inventory.FindAll().ToList();
            List <ItemTagsLocation> myItemsList = new List <ItemTagsLocation>();

            foreach (Inventory item in allItems)
            {
                ItemTagsLocation itemTagsLocation = new ItemTagsLocation();

                var roboDexerItems = _repo.Items.FindByCondition(i => i.ItemId == item.ItemId).SingleOrDefault();

                if (roboDexerItems == null)
                {
                    continue;
                }

                if (item.RoboDexerId == loggedInRoboDexer.RoboDexerId)
                {
                    var allInventory = _repo.Inventory.FindByCondition(i => i.ItemId == roboDexerItems.ItemId).SingleOrDefault();

                    //var tags = _repo.Tags.FindByCondition(i => i.TagId == roboDexerItems.TagId).SingleOrDefault();

                    var location = _repo.LocationPlace.FindByCondition(l => l.LocationId == roboDexerItems.LocationId).SingleOrDefault();

                    itemTagsLocation.Inventory = item;
                    itemTagsLocation.Items     = roboDexerItems;
                    //itemTagsLocation.Tags = tags;
                    itemTagsLocation.LocationPlace = location;

                    myItemsList.Add(itemTagsLocation);
                }
            }
            return(myItemsList);
        }
示例#2
0
        public IActionResult AddItem()
        {
            NavLayout();
            ItemTagsLocation itemsTagsLocation = new ItemTagsLocation();

            return(View(itemsTagsLocation));
        }
示例#3
0
        public ActionResult EditTheItem(int id, ItemTagsLocation itemTagsLocation)
        {
            NavLayout();
            var itemToEdit = _repo.Items.FindByCondition(i => i.ItemId == id).SingleOrDefault();

            itemToEdit = itemTagsLocation.Items;
            _repo.Items.Update(itemToEdit);

            var locationToEdit = _repo.LocationPlace.FindByCondition(l => l.LocationId == itemToEdit.LocationId).SingleOrDefault();

            locationToEdit = itemTagsLocation.LocationPlace;
            _repo.LocationPlace.Update(locationToEdit);

            ItemTags itemTags = new ItemTags();

            foreach (Tags tag in itemTagsLocation.Tags)
            {
                var items     = _repo.ItemTags.FindByCondition(i => i.TagsId == tag.TagId).SingleOrDefault();
                var tagToEdit = _repo.Tags.FindByCondition(t => t.TagId == items.TagsId).SingleOrDefault();
                tagToEdit.Name = tag.Name;
                _repo.Tags.Update(tagToEdit);
            }

            _repo.Save();
            try
            {
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
示例#4
0
        // GET: RoboDexerController/Edit/5
        public ActionResult EditItem(int id)
        {
            NavLayout();
            ItemTagsLocation itemToEnterIntoView = new ItemTagsLocation();

            var itemToEdit = _repo.Items.FindByCondition(i => i.ItemId == id).SingleOrDefault();

            itemToEnterIntoView.Items = itemToEdit;

            var locationToEdit = _repo.LocationPlace.FindByCondition(l => l.LocationId == itemToEdit.LocationId).SingleOrDefault();

            itemToEnterIntoView.LocationPlace = locationToEdit;

            var itemTags = _repo.ItemTags.FindByCondition(i => i.ItemId == itemToEdit.ItemId).ToList();

            List <Tags> listOfTags = new List <Tags>();

            foreach (ItemTags itemtag in itemTags)
            {
                var tags = _repo.Tags.FindByCondition(t => t.TagId == itemtag.TagsId).SingleOrDefault();
                listOfTags.Add(tags);
            }
            itemToEnterIntoView.Tags = listOfTags;
            //itemToEnterIntoView.Tags = tagsToEdit;

            return(View(itemToEnterIntoView));
        }
示例#5
0
        public async Task <IActionResult> AddItem(ItemTagsLocation itemTagsLocation)
        {
            NavLayout();
            //finds the logged in user
            var loggedInRoboDexer = FindLoggedInRoboDexer();

            //adds the item's location to the location table
            LocationPlace locationPlace = new LocationPlace();

            locationPlace.MainLocation      = itemTagsLocation.LocationPlace.MainLocation;
            locationPlace.SecondaryLocation = itemTagsLocation.LocationPlace.SecondaryLocation;
            _repo.LocationPlace.Create(locationPlace);
            _repo.Save();

            //adds all info into the item object and saves
            var itemObject = itemTagsLocation.Items;

            itemObject.LocationId = locationPlace.LocationId;
            itemObject.Price      = itemTagsLocation.Items.Price;
            itemObject.TimeAdded  = itemTagsLocation.Items.TimeAdded;
            _repo.Items.Create(itemObject);
            _repo.Save();

            //adds the item to the user's inventory
            Inventory inventory = new Inventory();

            inventory.ItemId      = itemObject.ItemId;
            inventory.RoboDexerId = loggedInRoboDexer.RoboDexerId;
            _repo.Inventory.Create(inventory);
            _repo.Save();


            //here the logic splits user input into spereate tags, adds tags to the table, and
            //then populates the itemtags table with the tags/item ids
            var listOfTags = itemTagsLocation.TagsInitial.Name.Split(' ').ToList();

            foreach (string tag in listOfTags)
            {
                Tags tags = new Tags();
                tags.Name = tag;
                _repo.Tags.Create(tags);
                _repo.Save();


                ItemTags itemTags = new ItemTags();
                itemTags.ItemId = itemObject.ItemId;
                itemTags.TagsId = tags.TagId;
                _repo.ItemTags.Create(itemTags);
                _repo.Save();
            }
            return(RedirectToAction("Index"));
        }
示例#6
0
        private ItemTagsLocation ConvertItemToItemTagsLocation(Items item)
        {
            //var tag = _repo.Tags.FindByCondition(t => t.TagId == item.TagId).SingleOrDefault();
            var location = _repo.LocationPlace.FindByCondition(l => l.LocationId == item.LocationId).SingleOrDefault();

            ItemTagsLocation itemTagsLocation = new ItemTagsLocation();

            itemTagsLocation.LocationPlace = location;
            //itemTagsLocation.Tags = tag;
            itemTagsLocation.Items = item;

            return(itemTagsLocation);
        }