Exemple #1
0
        static void Main(string[] args)
        {
            /*Entra a la clase CaffeineBeverage*/
            CaffeineBeverage caffeineBeverage;
            Coffe            coffe = new Coffe();
            Tea   tea           = new Tea();
            Coffe coffeWithMilk = new Coffe();
            Tea   teaWithLemon  = new Tea();

            Console.WriteLine("preparando Te (responder n)");
            tea.PrepareRecipe();
            Console.WriteLine("--------------------------------------------");
            Console.WriteLine("Preparando Cafe (responder n)");
            coffe.PrepareRecipe();
            Console.WriteLine("--------------------------------------------");
            Console.WriteLine("Preparando Cafe Con leche (responder y)");
            coffeWithMilk.PrepareRecipe();
            Console.WriteLine("--------------------------------------------");
            Console.WriteLine("preparando te con limon (responder y)");
            teaWithLemon.PrepareRecipe();
            Console.ReadLine();

            /*
             * Ejecuta el proyecto y observa como usando el mismo algoritmo podemos
             * variar pequeños aspectos de su funcionalidad.
             */
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReleaseDate,Intensity,Aroma,Type,HowToTake,Price")] Coffe coffe)
        {
            if (id != coffe.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(coffe);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CoffeExists(coffe.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(coffe));
        }
Exemple #3
0
        // PUT api/Coffes/5
        public IHttpActionResult PutCoffe(int id, Coffe coffe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != coffe.Id)
            {
                return(BadRequest());
            }

            db.Entry(coffe).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CoffeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Coffe coffe = db.Coffes.Find(id);

            db.Coffes.Remove(coffe);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        static void Main(string[] args)
        {
            BeverageWithCoffeine coffe = new Coffe();
            BeverageWithCoffeine tea   = new Tea();

            coffe.BrewingRecipe();
            Console.WriteLine();
            tea.BrewingRecipe();
            Console.ReadKey();
        }
Exemple #6
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Intensity,Aroma,Type,HowToTake")] Coffe coffe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(coffe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(coffe));
        }
Exemple #7
0
        public IHttpActionResult GetCoffe(int id)
        {
            Coffe coffe = db.Coffes.Find(id);

            if (coffe == null)
            {
                return(NotFound());
            }

            return(Ok(coffe));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Volume,CompanyId")] Coffe coffe)
 {
     if (ModelState.IsValid)
     {
         db.Entry(coffe).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CompanyId = new SelectList(db.Companies, "Id", "CompanyName", coffe.CompanyId);
     return(View(coffe));
 }
Exemple #9
0
        public IHttpActionResult PostCoffe(Coffe coffe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Coffes.Add(coffe);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = coffe.Id }, coffe));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Volume,CompanyId")] Coffe coffe)
        {
            if (ModelState.IsValid)
            {
                db.Coffes.Add(coffe);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CompanyId = new SelectList(db.Companies, "Id", "CompanyName", coffe.CompanyId);
            return(View(coffe));
        }
        // GET: /Coffe/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Coffe coffe = db.Coffes.Find(id);

            if (coffe == null)
            {
                return(HttpNotFound());
            }
            return(View(coffe));
        }
Exemple #12
0
        public void CoffeTest_ToString()
        {
            var c = new Coffe(1);

            Assert.Equal("C:1:0", c.ToString());

            var c1 = new Coffe(0);

            Assert.Equal("C::", c1.ToString());

            var c2 = new Coffe(2);

            Assert.Equal("C:2:0", c2.ToString());
        }
        public void AddCoffeToGroup(int groupId, CoffeViewModel coffeVM)
        {
            Group group = dataBase.Groups.Get(groupId);

            // Конфигурировани AutoMapper.
            Mapper.Reset();
            Mapper.Initialize(cfg => cfg.CreateMap <CoffeViewModel, Coffe>());
            Coffe coffe = Mapper.Map <Coffe>(coffeVM);

            coffe.GroupId = groupId;
            group.Coffes.Add(coffe);
            // Сохраняем изменения.
            dataBase.Save();
        }
Exemple #14
0
        public IHttpActionResult DeleteCoffe(int id)
        {
            Coffe coffe = db.Coffes.Find(id);

            if (coffe == null)
            {
                return(NotFound());
            }

            db.Coffes.Remove(coffe);
            db.SaveChanges();

            return(Ok(coffe));
        }
        // GET: /Coffe/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Coffe coffe = db.Coffes.Find(id);

            if (coffe == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CompanyId = new SelectList(db.Companies, "Id", "CompanyName", coffe.CompanyId);
            return(View(coffe));
        }
        static void Main(string[] args)
        {
            List <Coffe> coffeList = new List <Coffe>();

            string[] inputKeys = Console.ReadLine().Split();
            string   firstKey  = inputKeys[0].Trim();
            string   secondKey = inputKeys[1].Trim();

            while (true)
            {
                var    createCoffe = new Coffe();
                string inputCoffe  = Console.ReadLine();
                if (inputCoffe == "end of info")
                {
                    break;
                }
                if (inputCoffe.Contains(firstKey))
                {
                    string[] tokens =
                        inputCoffe.Split(new string[] { $"{firstKey}" }, StringSplitOptions.RemoveEmptyEntries);
                    string peopleDrinkingThisCoffe = tokens[0].Trim();
                    string coffeType = tokens[1].Trim();

                    foreach (var coffe in coffeList)
                    {
                        if (coffe.CofeeType.Contains(coffeType))
                        {
                            coffe.PeopleDrinkingThisCoffe.Add(peopleDrinkingThisCoffe);
                            break;
                        }
                    }
                    var result = coffeList.FindIndex(a => a.CofeeType == coffeType);
                    if (result == -1)
                    {
                        createCoffe.CofeeType = coffeType;
                        createCoffe.PeopleDrinkingThisCoffe = new List <string>();
                        createCoffe.DrinkingCoffesForWeek   = new List <int>();
                        createCoffe.PeopleDrinkingThisCoffe.Add(peopleDrinkingThisCoffe);

                        coffeList.Add(createCoffe);
                    }
                }
                else
                {
                    string[] tokens = inputCoffe.Split(new string[] { $"{secondKey}" },
                                                       StringSplitOptions.RemoveEmptyEntries);

                    string coffeType     = tokens[0].Trim();
                    int    coffeMaxCount = int.Parse(tokens[1].Trim());

                    int indexOfCurrentCoffe = coffeList.FindIndex(a => a.CofeeType == coffeType);

                    coffeList[indexOfCurrentCoffe].CoffeMaxCount += coffeMaxCount;
                    coffeList[indexOfCurrentCoffe].LeftCoffe     += coffeMaxCount;
                }
            }
            foreach (var zeroCoffe in coffeList)
            {
                if (zeroCoffe.LeftCoffe == 0)
                {
                    Console.WriteLine($"Out of {zeroCoffe.CofeeType}");
                }
            }

            while (true)
            {
                string drinkingCoffeThisWeek = Console.ReadLine();
                if (drinkingCoffeThisWeek == "end of week")
                {
                    break;
                }

                string[] weeksCoffes         = drinkingCoffeThisWeek.Split();
                string   peopleDrinkingCoffe = weeksCoffes[0].Trim();
                int      coffeCount          = int.Parse(weeksCoffes[1].Trim());

                foreach (var item in coffeList)
                {
                    if (item.PeopleDrinkingThisCoffe.Contains(peopleDrinkingCoffe))
                    {
                        int indexOfCurrentCoffe =
                            item.PeopleDrinkingThisCoffe.FindIndex(e => e.Equals(peopleDrinkingCoffe));

                        if (indexOfCurrentCoffe >= 0)
                        {
                            item.DrinkingCoffesForWeek.Add(coffeCount);
                            item.LeftCoffe -= coffeCount;
                            if (item.LeftCoffe <= 0)
                            {
                                Console.WriteLine($"Out of {item.CofeeType}");
                            }
                            break;
                        }
                    }
                }
            }
            Console.WriteLine("Coffee Left:");
            foreach (var coffeType in coffeList.OrderByDescending(a => a.LeftCoffe))
            {
                int totalDrinkingCoffeForType = coffeType.DrinkingCoffesForWeek.Sum();

                if (coffeType.CoffeMaxCount > totalDrinkingCoffeForType)
                {
                    int totalLeftCoffeForType = coffeType.CoffeMaxCount - totalDrinkingCoffeForType;
                    coffeType.LeftCoffe = totalLeftCoffeForType;
                    Console.WriteLine($"{coffeType.CofeeType} {totalLeftCoffeForType}");
                }
            }
            Console.WriteLine("For:");
            foreach (var item in coffeList.OrderBy(a => a.CofeeType))
            {
                foreach (var peope in item.PeopleDrinkingThisCoffe.OrderByDescending(a => a))
                {
                    if (item.LeftCoffe > 0)
                    {
                        Console.WriteLine($"{peope} {item.CofeeType}");
                    }
                }
            }
        }
 public Milk(Coffe coffe)
 {
     Price = 5.00;
     Coffe = coffe;
 }
 public CoffeDecorator(Coffe coffeComponent)
 {
     CoffeComponent = coffeComponent;
 }
Exemple #19
0
 public Mocha(Coffe coffe)
 {
     Price = 5.00;
     Coffe = coffe;
 }
 public Soya(Coffe coffe)
 {
     Price = 7.00;
     Coffe = coffe;
 }