public void DeleteSnack(ISnack record)
    {
        if (record == null)
        {
            return;
        }
        Snack _record_;
        var   deletionList = new System.Collections.Generic.HashSet <IDelRecord>();

        if (!_snack_pk.TryGetValue(record.Id, out _record_))
        {
            throw new ArgumentException(String.Format(
                                            "'Snack' with id '{0}' does not exist.",
                                            record.Id));
        }
        _record_.PreDeleteOuter(deletionList, false);
        foreach (IDelRecord item in deletionList)
        {
            item.EnsureCanDelete(deletionList);
        }
        foreach (IDelRecord item in deletionList)
        {
            item.DoDelete(this, deletionList);
        }
    }
        public ISnack Add(ISnack snack)
        {
            snack.Id = _snacks.Max(x => x.Id) + 1;
            _snacks.Add(snack);

            return(snack);
        }
    public ISnack CreateSnack(IHuman owner, decimal price, string taste)
    {
        // item 391
        ISnack snack = InsertSnack(0);

        snack.Taste = taste;
        snack.Price = price;
        SetItemOwner(snack, owner);
        // item 286
        return(snack);
    }
Exemple #4
0
        [HttpPost] //Add route cosntraint for httpPost Create request
        public IActionResult VoteChip(ChipEditModel model)
        {
            if (ModelState.IsValid)//ModelState is a framework property that checks your POST bindings
            {
                ISnack newSnack = null;

                newSnack           = new Chip();
                newSnack.Flavor    = model.Flavor;
                newSnack.SnackType = SnackType.Chip;  //uses POST - REDIRECT - GET Pattern, POST is for write, GET is for read

                newSnack = (OdeToFood.Models.Chip.Chip)_snackData.Add(newSnack);
                return(RedirectToAction(nameof(ChipDetails), new { id = newSnack.Id }));

                //return View("Details", newRestaurant); //Used for POST request


                return(View()); //This redirect action makes it POST safe
            }
            else
            {
                return(View());
            }
        }
 public void WhenCreateAnotherSnack()
 {
     _anotherSnack = new Snack(_user);
 }
 public void WhenICreateASnack()
 {
     _snack = new Snack(_user);
 }
Exemple #7
0
 public static void setHousekeeping(ISnack aSnack)
 // This provides a seam in the factory where I can prime the factory with the user it will then cough up. (for test code)
 {
     snack = aSnack;
 }