Beispiel #1
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"));
        }
 public void SaveLocationPlace(LocationPlace newLocationPlace)
 {
     if (newLocationPlace.Id == 0)
     {
         dbContext.LocationPlaces.Add(newLocationPlace);
     }
     else
     {
         var curLocationPlace = dbContext.LocationPlaces.Single(o => o.Id == newLocationPlace.Id);
         curLocationPlace.LocationName = newLocationPlace.LocationName;
     }
     dbContext.SaveChanges();
 }
Beispiel #3
0
        public ActionResult SaveLocationPlace(LocationPlaceModel newLocation)
        {
            if (ModelState.IsValid)
            {
                var saveLocationPlace = new LocationPlace
                {
                    Id           = newLocation.Id,
                    LocationName = newLocation.LocationName
                };

                locationPlaceService.SaveLocationPlace(saveLocationPlace);

                return(RedirectToAction("Index"));
            }

            return(View("EditLocationPlace", newLocation));
        }