示例#1
0
        public IActionResult Create([Bind("ItemName,StoreName,SellerName,TopicName,ItemName,ItemDescription,ItemPrice")] ItemViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var myStore  = RepoStore.GetStoresByName().First(p => p.Name.ToLower() == viewModel.StoreName.ToLower()).Id;
                    var mySeller = RepoSell.GetSellersByName().First(p => p.Name.ToLower() == viewModel.SellerName.ToLower()).Id;
                    var myTopic  = RepoTopi.GetTopicByName().First(p => p.Topic.ToLower() == viewModel.TopicName.ToLower()).Id;
                    var item     = new Domain.Model.Item
                    {
                        Id          = 0,
                        Name        = viewModel.ItemName,
                        Description = viewModel.ItemDescription,
                        Price       = viewModel.ItemPrice,
                        StoreId     = myStore,
                        OrderId     = viewModel.OrderId,
                        SellerId    = mySeller,
                        TopicId     = myTopic
                    };
                    Repo.AddItem(item);
                    Repo.Save();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(viewModel));
            }
            catch
            {
                return(View(viewModel));
            }
        }
 /// <summary>
 /// Checks FindItem to make sure it returns null correctly if Item quantity is too high
 /// </summary>
 public void WrongItemShouldNotBeFound()
 {
     using (var context = new Entity.FannerDogsDBContext(options))
     {
         IRepo            _repoDS    = new Repo(context);
         Model.DogManager dogManager = new Model.DogManager(1234567890, "Test, TX", "Texas Toaster");
         _repoDS.AddManager
         (
             dogManager
         );
         Model.StoreLocation storeLocation = new Model.StoreLocation("Test, TX", "Test Dogs");
         _repoDS.AddStoreLocation(
             storeLocation,
             dogManager
             );
         Model.Dog dog = new Model.Dog("Special Breed", 'f', 1000);
         _repoDS.AddItem(
             storeLocation,
             dog,
             5
             );
         Model.Item item = _repoDS.FindItem(
             storeLocation,
             dog,
             20
             );
         bool itemNotThere = (item == null);
         bool expected     = true;
         Assert.Equal(itemNotThere, expected);
     }
 }
 /// <summary>
 /// Makes sure store inventory is being updated
 /// </summary>
 public void AddItemShouldBeInStoreInventory()
 {
     using (var context = new Entity.FannerDogsDBContext(options))
     {
         IRepo            _repoDS    = new Repo(context);
         Model.DogManager dogManager = new Model.DogManager(1234567890, "Test, TX", "Texas Toaster");
         _repoDS.AddManager
         (
             dogManager
         );
         Model.StoreLocation storeLocation = new Model.StoreLocation("Test, TX", "Test Dogs");
         _repoDS.AddStoreLocation(
             storeLocation,
             dogManager
             );
         Model.Dog dog = new Model.Dog("Special Breed", 'f', 1000);
         _repoDS.AddItem(
             storeLocation,
             dog,
             5
             );
         List <Model.Item> items = _repoDS.GetStoreInventory(
             storeLocation.Address,
             storeLocation.Location
             );
         int expected = 1;
         Assert.Equal(items.Count(), expected);
     }
 }
示例#4
0
 static void Add()
 {
     if (PromptFileAndTags(out var fn, out var tags))
     {
         var kf = new Rox.Core.File {
             Path = fn
         };
         if (_repo.All.TryGetValue(kf, out var f))
         {
             kf = (Rox.Core.File)f;
         }
         kf.Tags.UnionWith(tags.Select(t => new Tag(t)));
         _repo.AddItem(kf);
     }
 }
 public Item AddItem(StoreLocation store, Dog dog, int quant)
 {
     return(_repoDS.AddItem(store, dog, quant));
 }