Beispiel #1
0
        public void Purchase(decimal currentFunds, string vendingChoice)
        {
            var vendinglist = f.GrabInfo();
            var list        = vendinglist.ToList();

            foreach (var v in list)
            {
                if (v.Value.Location == vendingChoice)
                {
                    if (currentFunds >= v.Value.Price)
                    {
                        Console.WriteLine($"You have purchased {v.Value.Name}");

                        Console.ReadKey();
                        v.Value.Inventory--;
                        var result = f.Update(vendinglist);
                        if (result == true)
                        {
                            Console.WriteLine("The item inventory has successfully be updated.");
                        }
                        else
                        {
                            Console.WriteLine("The file has not been updated......");
                        }
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("You do not have enough funds, please enter more!");
                        Console.ReadKey();
                    }
                }
            }
        }
        public IHttpActionResult Put(int id, FileDto file)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != file.FileId)
            {
                return(BadRequest());
            }
            try
            {
                fileRepo.Update(Mapper.Map <File>(file));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FileExists(id))
                {
                    return(Content(HttpStatusCode.NotFound, "Item does not exist"));
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }