Пример #1
0
        public void InsertCupcake(Cupcake cupcake)
        {
            var connection = createConnection();

            connection.Open();
            SqlCommand command = new SqlCommand()
            {
                CommandText = "INSERT INTO Cupcake VALUES (@Name, @Price, @CreatedOn, @LastModified, @Ingredients, @ImageFileName, @Featured)",
                Connection  = connection
            };
            SqlParameter priceParemeter = new SqlParameter()
            {
                ParameterName = "Price",
                DbType        = System.Data.DbType.Decimal,
                Value         = cupcake.Price,
                SqlDbType     = System.Data.SqlDbType.Decimal,
                SqlValue      = cupcake.Price
            };

            command.Parameters.AddWithValue("Name", cupcake.Name);
            command.Parameters.Add(priceParemeter);
            command.Parameters.AddWithValue("CreatedOn", cupcake.CreatedOn);
            command.Parameters.AddWithValue("LastModified", cupcake.LastModified);
            command.Parameters.AddWithValue("Ingredients", cupcake.Ingredients);
            command.Parameters.AddWithValue("ImageFileName", cupcake.ImageFileName == null ? "" : cupcake.ImageFileName);
            command.Parameters.AddWithValue("Featured", cupcake.Featured);
            command.ExecuteNonQuery();
            connection.Close();
        }
Пример #2
0
        public void UpdateCupcake(Cupcake cupcake)
        {
            //create connection string and update cupcake
            var connection = createConnection();

            connection.Open();
            SqlCommand command = new SqlCommand()
            {
                CommandText = "UPDATE Cupcake SET Name = @Name, Price = @Price, LastModified = @LastModified, Ingredients = @Ingredients, ImageFileName = @ImageFileName, Featured = @Featured WHERE Id = @Id",
                Connection  = connection
            };

            SqlParameter priceParemeter = new SqlParameter()
            {
                ParameterName = "Price",
                DbType        = System.Data.DbType.Decimal,
                Value         = cupcake.Price,
                SqlDbType     = System.Data.SqlDbType.Decimal,
                SqlValue      = cupcake.Price
            };

            command.Parameters.AddWithValue("Name", cupcake.Name);
            command.Parameters.Add(priceParemeter);
            command.Parameters.AddWithValue("LastModified", cupcake.LastModified);
            command.Parameters.AddWithValue("Id", cupcake.Id);
            command.Parameters.AddWithValue("Ingredients", cupcake.Ingredients);
            command.Parameters.AddWithValue("ImageFileName", cupcake.ImageFileName);
            command.Parameters.AddWithValue("Featured", cupcake.Featured);
            command.ExecuteNonQuery();
            connection.Close();
        }
Пример #3
0
        public IActionResult Create(string newName, string newDescription, int newPrice, string newCake, string newFrosting, string newTopping, int newInventory, string newImage)
        {
            Cupcake newCupcake = new Cupcake(newName, newDescription, newPrice, newCake, newFrosting, newTopping, newInventory, newImage);

            cupcakeRepo.Save(newCupcake);
            return(Json(newCupcake));
        }
Пример #4
0
        public IActionResult DeleteConfirmed(int id)
        {
            Cupcake thisCupcake = cupcakeRepo.Cupcakes.FirstOrDefault(x => x.Id == id);

            cupcakeRepo.Remove(thisCupcake);
            return(Json(thisCupcake));
        }
Пример #5
0
        /// <summary>
        /// Fired when the game updates.
        /// </summary>
        /// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param>
        private static void Game_OnUpdate(EventArgs args)
        {
            try
            {
                Game.PrintChat(Cupcake.Initialized.ToString());
                if (!Cupcake.Initialized)
                {
                    return;
                }
            }
            catch (Exception)
            {
                // ignored
            }


            foreach (var spell in SpellList)
            {
                var target = TargetSelector.GetTarget(spell.Range, TargetSelector.DamageType.True);

                if (target == null)
                {
                    continue;
                }

                var prediction = Cupcake.GetPrediction(new CupcakeIngredients(target, spell)).CastPosition;
                spell.Cast(prediction);
            }
        }
Пример #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            Cupcake cupcake = context.Cupcakes.Find(id);

            context.Cupcakes.Remove(cupcake);
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public IGraphActionResult NewCupcakeCreated(Cupcake eventData, string nameLike = "*")
        {
            if (this.IsMatch(eventData, nameLike))
            {
                return(this.Ok(eventData));
            }

            return(this.Ok());
        }
        public void AddAsync_throws_if_model_is_null()
        {
            IInventoryRepository repository = new InventoryRepository(_context);


            Cupcake cupcake = null;

            Assert.ThrowsAsync <ArgumentException>(() => repository.AddAsync(cupcake));
        }
Пример #9
0
 public IActionResult CreatePost(Cupcake cupcake)
 {
     if (ModelState.IsValid)
     {
         _repository.CreateCupcake(cupcake);
         return(RedirectToAction(nameof(Index)));
     }
     PopulateBakeriesDropDownList(cupcake.BakeryId);
     return(View(cupcake));
 }
        public void Database_GetDetailsPage_SelectedCupcakeIsReturned()
        {
            CupcakeController controller = new CupcakeController(db);
            var testCupcake = new Cupcake("Limoncello Meringue", "Vanilla cake with marshmallow frosting, browned to perfection.", 2, "Vanilla", "Marshmallow", "None", 24, "http://www.cupcakeroyale.com/wp-content/uploads/2016/04/Limoncello.jpg");

            controller.Create(testCupcake);
            var model = (controller.Details(testCupcake.Id) as ViewResult).ViewData.Model as Cupcake;

            Assert.Equal(testCupcake, model);
        }
        public void Database_CreateNewCupcake_CupcakeIsReturned()
        {
            CupcakeController controller = new CupcakeController(db);
            var testCupcake = new Cupcake("Limoncello Meringue", "Vanilla cake with marshmallow frosting, browned to perfection.", 2, "Vanilla", "Marshmallow", "None", 24, "http://www.cupcakeroyale.com/wp-content/uploads/2016/04/Limoncello.jpg");

            controller.Create(testCupcake);
            var collection = (controller.Index() as ViewResult).ViewData.Model as IEnumerable <Cupcake>;

            Assert.Contains(testCupcake, collection);
        }
Пример #12
0
        public ActionResult Delete(int id)
        {
            Cupcake cupcake = context.Cupcakes.Find(id);

            if (cupcake == null)
            {
                return(HttpNotFound());
            }
            return(View("Delete", cupcake));
        }
Пример #13
0
 public ActionResult Create(Cupcake cupcake)
 {
     if (!ModelState.IsValid)
     {
         return(View("Create", cupcake));
     }
     context.Cupcakes.Add(cupcake);
     context.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #14
0
        public IActionResult Edit(int id)
        {
            Cupcake cupcake = _repository.GetCupcakeById(id);

            if (cupcake == null)
            {
                return(NotFound());
            }
            PopulateBakeriesDropDownList(cupcake.BakeryId);
            return(View(cupcake));
        }
Пример #15
0
        public async Task AddAsync(Cupcake cupcake)
        {
            if (cupcake == null)
            {
                throw new ArgumentException("Cupcake cannot be null", nameof(cupcake));
            }

            _context.Cupcakes.Add(cupcake);

            await _context.SaveChangesAsync();
        }
Пример #16
0
        public void GetNameTest()
        {
            //Arrange
            var cupcake = new Cupcake("Rhubarb Almond Buckle", "Our vanilla cupcake filled with a tangy rhubarb compote, topped with fresh strawberry buttercream and almond streusel. Available May only!", 3, "Almond", "Rhubarb", "Almonds", 36, "http://www.cupcakeroyale.com/wp-content/uploads/2016/03/Rhubarb-Crisp-084.jpg");

            //Act
            var result = cupcake.Name;

            //Assert
            Assert.Equal("Rhubarb Almond Buckle", result);
        }
        public async Task AddAsync_inserts_model_into_repository()
        {
            IInventoryRepository repository = new InventoryRepository(_context);

            Cupcake cupcake = new Cupcake {
                Name = "FooBar Sprinkles"
            };

            await repository.AddAsync(cupcake);

            var savedCupcake = Assert.Single(_context.Cupcakes);

            Assert.Equal(cupcake.Name, savedCupcake.Name);
        }
Пример #18
0
 public void CreateCupcake(Cupcake cupcake)
 {
     if (cupcake.PhotoAvatar != null && cupcake.PhotoAvatar.Length > 0)
     {
         cupcake.ImageMimeType = cupcake.PhotoAvatar.ContentType;
         cupcake.ImageName     = Path.GetFileName(cupcake.PhotoAvatar.FileName);
         using (var ms = new MemoryStream())
         {
             cupcake.PhotoAvatar.CopyTo(ms);
             cupcake.PhotoFile = ms.ToArray();
         }
         _context.Add(cupcake);
         _context.SaveChanges();
     }
 }
Пример #19
0
 public async Task <IActionResult> EditPost(int id, Cupcake cupcake)
 {
     if (_repository.GetCupcakeById(id) is Cupcake cupcakeToUpdate)
     {
         if (await TryUpdateModelAsync(cupcakeToUpdate, prefix: "",
                                       c => c.BakeryId, c => c.CupcakeType, c => c.Description, c => c.GlutenFree, c => c.Price))
         {
             _repository.SaveChanges();
             return(RedirectToAction(nameof(Index)));
         }
         PopulateBakeriesDropDownList(cupcakeToUpdate.BakeryId);
         return(View(cupcakeToUpdate));
     }
     return(NotFound());
 }
Пример #20
0
 public void CreateCupcake(Cupcake cupcake)
 {
     if (cupcake.PhotoAvatar?.Length > 0)
     {
         cupcake.ImageMimeType = cupcake.PhotoAvatar.ContentType;
         cupcake.ImageName     = cupcake.PhotoAvatar.FileName;
         using (var memoryStream = new MemoryStream())
         {
             cupcake.PhotoAvatar.CopyTo(memoryStream);
             cupcake.PhotoFile = memoryStream.ToArray();
         }
     }
     _context.Add(cupcake);
     _context.SaveChanges();
 }
Пример #21
0
        public IActionResult Edit(string newName, string newDescription, int newPrice, string newCake, string newFrosting, string newTopping, int newInventory, string newImage, int id)
        {
            Cupcake thisCupcake = cupcakeRepo.Cupcakes.FirstOrDefault(x => x.Id == id);

            thisCupcake.Name        = newName;
            thisCupcake.Description = newDescription;
            thisCupcake.Price       = newPrice;
            thisCupcake.Cake        = newCake;
            thisCupcake.Frosting    = newFrosting;
            thisCupcake.Topping     = newTopping;
            thisCupcake.Inventory   = newInventory;
            thisCupcake.ImgUrl      = newImage;

            cupcakeRepo.Edit(thisCupcake);
            return(Json(thisCupcake));
        }
Пример #22
0
 public void CreateCupcake(Cupcake cupcake)
 {
     if (cupcake.PhotoAvatar is not null)
     {
         if (cupcake.PhotoAvatar.Length > 0)
         {
             cupcake.ImageMimeType         = cupcake.PhotoAvatar.ContentType;
             cupcake.ImageName             = Path.GetFileName(cupcake.PhotoAvatar.FileName);
             using MemoryStream _ctxMemory = new();
             cupcake.PhotoAvatar.CopyTo(_ctxMemory);
             cupcake.PhotoFile = _ctxMemory.ToArray();
         }
     }
     _ = _context.Add(cupcake);
     _ = _context.SaveChanges();
 }
Пример #23
0
        public void DeleteCupcake(Cupcake cupcake)
        {
            //create connection string and delete cupcake
            var connection = createConnection();

            connection.Open();
            SqlCommand command = new SqlCommand()
            {
                CommandText = "DELETE Cupcake WHERE Id = @Id",
                Connection  = connection
            };

            command.Parameters.AddWithValue("Id", cupcake.Id);
            command.ExecuteNonQuery();
            connection.Close();
        }
Пример #24
0
        public IGraphActionResult UpdateCupcake(Cupcake cupcake)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var updatedCake = _cupcakeService.UpdateCupcake(cupcake.Id ?? -1, cupcake.Name, cupcake.Flavor);

            if (updatedCake == null)
            {
                return(this.BadRequest("Cupcake not found"));
            }

            this.PublishSubscriptionEvent(PastryConstants.CUPCAKE_UPDATED, updatedCake);
            return(this.Ok(updatedCake));
        }
Пример #25
0
        public IGraphActionResult AddCupcake(Cupcake cupcake)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var updatedCake = _cupcakeService.CreateCupcake(cupcake.Name, cupcake.Flavor, cupcake.Quantity);

            if (updatedCake == null)
            {
                return(this.BadRequest("Error creating the new cupcake"));
            }

            this.PublishSubscriptionEvent(PastryConstants.CUPCAKE_CREATED, updatedCake);
            return(this.Ok(updatedCake));
        }
Пример #26
0
        private static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Gang of Four Design Pattern - Decorator");

            IDessert cookie = new Cookie {
                BatterFlavor = "Vanilla", HasFrosting = true, FrostingFlavor = "Buttercream", UnitCost = .89m
            };

            cookie.UpdatePrice(1.99m);

            IDessert cake = new Cake {
                BatterFlavor = "Chocolate", HasFrosting = true, FrostingFlavor = "German Chocolate", UnitCost = 5.99m
            };

            cake.UpdatePrice(12.99m);

            IDessert cupcake = new Cupcake()
            {
                BatterFlavor = "Red Velvet", HasFrosting = true, FrostingFlavor = "Cream cheese", UnitCost = 1.39m
            };

            cupcake.UpdatePrice(3.99m);

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(cookie.GetDetails());

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(cake.GetDetails());

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine(cupcake.GetDetails());

            Console.ForegroundColor = ConsoleColor.White;

            var offer = new DayOldDessertDecorator(cupcake)
            {
                DiscountPercentage = 25, Offer = "25% Day Old"
            };

            offer.ApplyDiscount();

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine($"{offer.Offer}  {offer.GetDetails()}");
        }
Пример #27
0
        public static CupcakeModel ToModel(this Cupcake cupcake)
        {
            //convert entity to model
            var model = new CupcakeModel();

            model.Id                  = cupcake.Id;
            model.Name                = cupcake.Name;
            model.Price               = cupcake.Price;
            model.CreatedOn           = (DateTime?)cupcake.CreatedOn;
            model.LastModified        = (DateTime?)cupcake.LastModified;
            model.Ingredients         = cupcake.Ingredients;
            model.NumberOfIngredients = cupcake.Ingredients.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)
                                        .Select(x => !string.IsNullOrEmpty(x))
                                        .ToList().Count;
            model.ImageFileName = cupcake.ImageFileName;
            model.Featured      = cupcake.Featured;

            return(model);
        }
Пример #28
0
        private static void AddTestData(GitTrioContext context)
        {
            context.Database.ExecuteSqlCommand("Delete From Cupcakes");
            context.Database.ExecuteSqlCommand("Delete From Users");

            var cupcake1 = new Cupcake("Limoncello Meringue", "Vanilla cake with marshmallow frosting, browned to perfection.", 2, "Vanilla", "Marshmallow", "None", 24, "http://www.cupcakeroyale.com/wp-content/uploads/2016/04/Limoncello.jpg");

            context.Cupcakes.Add(cupcake1);

            var cupcake2 = new Cupcake("Rhubarb Almond Buckle", "Our vanilla cupcake filled with a tangy rhubarb compote, topped with fresh strawberry buttercream and almond streusel. Available May only!", 3, "Almond", "Rhubarb", "Almonds", 36, "http://www.cupcakeroyale.com/wp-content/uploads/2016/03/Rhubarb-Crisp-084.jpg");

            context.Cupcakes.Add(cupcake2);

            var user1 = new User("user1", "password");

            context.Users.Add(user1);

            context.SaveChanges();
        }
        public void Database_DeleteDatabaseObject_SelectedCupcakeIsDeleted()
        {
            CupcakeController controller = new CupcakeController(db);

            var testCupcake = new Cupcake("Limoncello Meringue", "Vanilla cake with marshmallow frosting, browned to perfection.", 2, "Vanilla", "Marshmallow", "None", 24, "http://www.cupcakeroyale.com/wp-content/uploads/2016/04/Limoncello.jpg");

            controller.Create(testCupcake);

            var testCupcake2 = new Cupcake("Red Velvet", "Vanilla cake with marshmallow frosting, browned to perfection.", 2, "Chocolate", "Marshmallow", "None", 24, "http://www.cupcakeroyale.com/wp-content/uploads/2016/04/Limoncello.jpg");

            controller.Create(testCupcake2);
            controller.DeleteConfirmed(testCupcake2.Id);

            List <Cupcake> expected = new List <Cupcake> {
                testCupcake
            };

            var collection = (controller.Index() as ViewResult).ViewData.Model as IEnumerable <Cupcake>;

            Assert.Equal(expected, collection);
        }
Пример #30
0
        public static Cupcake ToEntity(this CupcakeModel model)
        {
            //convert model to entity
            var cupcake = new Cupcake();

            cupcake.Id           = model.Id;
            cupcake.Name         = model.Name;
            cupcake.Price        = model.Price;
            cupcake.Ingredients  = model.Ingredients;
            cupcake.LastModified = DateTime.Now;
            if (cupcake.Id == 0)
            {
                cupcake.CreatedOn = DateTime.Now;
            }
            if (!string.IsNullOrEmpty(model.ImageFileName))
            {
                cupcake.ImageFileName = model.ImageFileName;
            }
            cupcake.Featured = model.Featured;

            return(cupcake);
        }