public void UpdateGroceryItemQuery(GroceryItem Request)
        {
            // Create and Open Database Connection
            var connectionString  = GetConnectionString();
            NpgsqlConnection conn = new NpgsqlConnection(connectionString);

            conn.Open();

            // Define Query
            string sql =
                "UPDATE " +
                "GroceryItems SET quantity = (quantity + :quantity) " +
                "WHERE name = :name;";

            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            cmd.Parameters.Add(new NpgsqlParameter("name", NpgsqlTypes.NpgsqlDbType.Text));
            cmd.Parameters[0].Value = Request.name.ToUpper();
            cmd.Parameters.Add(new NpgsqlParameter("quantity", NpgsqlTypes.NpgsqlDbType.Integer));
            cmd.Parameters[1].Value = Request.quantity;

            // Execute Query
            cmd.ExecuteNonQuery();

            // Close Database Connection
            conn.Close();
        }
        public async Task <IActionResult> PutGroceryItem(long id, GroceryItem groceryItem)
        {
            if (id != groceryItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(groceryItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroceryItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public EditGroceryItemViewModel(GroceryItem item) : base()
 {
     // Use Cheese object to initialize the ViewModel properties
     GroceryId   = item.ID;
     Name        = item.Name;
     GroceryNote = item.GroceryNote;
 }
        public async Task <ActionResult <GroceryItem> > PostGroceryItem(GroceryItem groceryItem)
        {
            _context.GroceryItem.Add(groceryItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGroceryItem", new { id = groceryItem.Id }, groceryItem));
        }
Beispiel #5
0
        private void meatButton_Click(object sender, EventArgs e)
        {
            GroceryItem steak   = new GroceryItem("Steak");
            GroceryItem chicken = new GroceryItem("Chicken");
            GroceryItem pork    = new GroceryItem("Pork");
            GroceryItem lamb    = new GroceryItem("Lamb");
            GroceryItem veal    = new GroceryItem("Veal");

            List <GroceryItem> itemList = new List <GroceryItem>();

            itemList.Add(steak);
            itemList.Add(chicken);
            itemList.Add(pork);
            itemList.Add(lamb);
            itemList.Add(veal);


            Category meat = new Category("Meat", itemList);


            Form1 f = new Form1(meat);

            f.Show();
            this.Hide();
        }
Beispiel #6
0
        public List <GroceryItem> GetGroceryItemsMapper(NpgsqlDataReader dataReader)
        {
            List <GroceryItem> groceryList = new List <GroceryItem>();

            try
            {
                while (dataReader.Read())
                {
                    GroceryItem groceryItem = new GroceryItem
                    {
                        name     = dataReader["Name"].ToString(),
                        quantity = (int)dataReader["Quantity"]
                    };

                    groceryList.Add(groceryItem);
                }
            }
            catch (NpgsqlException e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(groceryList);
        }
Beispiel #7
0
        //item stocked is true and foundAisle is true and first check is false and inventory is empty
        public NodeVal checkItemFirst()
        {
            foreach (Aisle a in closeAisles)
            {
                for (int i = 0; i < a.itemsOnShelf.Length; i++)
                {
                    //set item you are checking
                    GroceryItem checkingItem = a.itemsOnShelf[i];
                    Stock       itemShelf    = checkingItem.Shelf;
                    if (itemShelf.currentStock < _minShelfStockAccepted)
                    {
                        //found an item that needs to be stocked
                        //AislesChecked = 0;
                        itemStocked       = false;
                        targetGrocery     = checkingItem;
                        targetStock       = targetGrocery.Supply;
                        movingToStockRoom = true;
                        return(NodeVal.Success);
                    }
                }
            }


            //both aisles are minimally stocked, check next one
            CheckedPoints += 1;
            foundAisle     = false;
            return(NodeVal.Success);
        }
Beispiel #8
0
        public async Task <IActionResult> RemoveFromGrocery(int[] groceryIds)
        {
            // used checkboxes, looping through list of cheeseIds
            foreach (int groceryId in groceryIds)
            {
                // accessing the existing cheese object
                GroceryItem theItem = Context.GroceryItems.Single(c => c.ID == groceryId);


                // checking if the user is allowed to delete items from the pantry
                var isAuthorized = await AuthorizationService.AuthorizeAsync(
                    User, theItem,
                    FoodOperations.Delete);

                if (!isAuthorized.Succeeded)
                {
                    return(Forbid());
                }

                // removing each cheese in the list from the database
                Context.GroceryItems.Remove(theItem);
            }

            // saving changes to the database
            Context.SaveChanges();

            // redirecting back to the index to show grocery list
            return(Redirect("/Grocery"));
        }
Beispiel #9
0
        //item stocked is true and aisle found false is true and first check is true
        public NodeVal checkItemSecond()
        {
            foreach (Aisle a in closeAisles)
            {
                for (int i = 0; i < a.itemsOnShelf.Length; i++)
                {
                    //set item you are checking
                    GroceryItem checkingItem = a.itemsOnShelf[i];
                    Stock       itemShelf    = checkingItem.Shelf;
                    if (itemShelf.currentStock < itemShelf.stockMaxSize) //this is the difference between check first and check second
                    {
                        //found an item that needs to be stocked
                        //AislesChecked = 0;
                        itemStocked       = false;
                        targetGrocery     = checkingItem;
                        targetStock       = targetGrocery.Supply;
                        movingToStockRoom = true;
                        return(NodeVal.Success);
                    }
                }
            }


            //both aisles are max stocked, check next one
            CheckedPoints += 1;
            foundAisle     = false;
            return(NodeVal.Success);
        }
Beispiel #10
0
        public async Task <IActionResult> EditGroceryItem(EditGroceryItemViewModel vm)
        {
            GroceryItem editedGroceryItem = Context.GroceryItems.Single(c => c.ID == vm.GroceryId);

            var isAuthorized = await AuthorizationService.AuthorizeAsync(
                User, editedGroceryItem, FoodOperations.Update);

            var currentUserId = UserManager.GetUserId(User);

            if (!isAuthorized.Succeeded)
            {
                return(Forbid());
            }

            if (ModelState.IsValid)
            {
                editedGroceryItem.Name        = vm.Name;
                editedGroceryItem.GroceryNote = vm.GroceryNote;

                Context.SaveChanges();
                return(Redirect("/Grocery"));
            }

            EditGroceryItemViewModel newEditViewModel = new EditGroceryItemViewModel(editedGroceryItem);

            newEditViewModel.GroceryList = Context.GroceryItems.Where(g => g.IsInPantry == false).Where(g => g.UserID == currentUserId).ToList();

            return(View(newEditViewModel));
        }
Beispiel #11
0
        private void deliButton_Click(object sender, EventArgs e)
        {
            GroceryItem sandwich     = new GroceryItem("Sandwich");
            GroceryItem salad        = new GroceryItem("Salad");
            GroceryItem wrap         = new GroceryItem("Wrap");
            GroceryItem slicedmeat   = new GroceryItem("Sliced Meat");
            GroceryItem slicedcheese = new GroceryItem("Sliced Cheese");

            List <GroceryItem> itemList = new List <GroceryItem>();

            itemList.Add(sandwich);
            itemList.Add(salad);
            itemList.Add(wrap);
            itemList.Add(slicedmeat);
            itemList.Add(slicedcheese);


            Category deli = new Category("Deli", itemList);


            Form1 f = new Form1(deli);

            f.Show();
            this.Hide();
        }
Beispiel #12
0
        private void seafoodButton_Click(object sender, EventArgs e)
        {
            GroceryItem salmon  = new GroceryItem("Salmon");
            GroceryItem trout   = new GroceryItem("Trout");
            GroceryItem shrimp  = new GroceryItem("Shrimp");
            GroceryItem crab    = new GroceryItem("Crab");
            GroceryItem lobster = new GroceryItem("Lobster");

            List <GroceryItem> itemList = new List <GroceryItem>();

            itemList.Add(salmon);
            itemList.Add(trout);
            itemList.Add(shrimp);
            itemList.Add(crab);
            itemList.Add(lobster);


            Category seafood = new Category("Seafood", itemList);


            Form1 f = new Form1(seafood);

            f.Show();
            this.Hide();
        }
        public async Task <IActionResult> AddGrocery([FromBody] GroceryItem grocery, [FromRoute] int shopId)
        {
            var newGroceryItem = await _grocceryItemService.AddItemToList(shopId, grocery);

            if (newGroceryItem == null)
            {
                return(BadRequest(new BaseResponse <string>()
                {
                    Succes = false,
                    Error = "no shop found with this shopId"
                }));
            }

            var signalrRoom = await _grocceryItemService.GetSignalrRoom(shopId);

            if (signalrRoom == null)
            {
                return(BadRequest(new BaseResponse <string>()
                {
                    Succes = false,
                    Error = "No signalr group found for this grocery list"
                }));
            }
            var shopResponse = await _shopService.GetShopByShopId(shopId);

            await _groceryItemHub.Clients.Group(signalrRoom).SendAsync(nameof(IGroceryItemHub.NewGroceryAdded), newGroceryItem);

            await _shopHub.Clients.Group("Test-5").SendAsync(nameof(IShopHub.UpdateShop), shopResponse);

            return(Created("https://shoppinglist.dallau.com", newGroceryItem));
        }
Beispiel #14
0
        private void dairyButton_Click(object sender, EventArgs e)
        {
            GroceryItem milk   = new GroceryItem("Milk");
            GroceryItem butter = new GroceryItem("Butter");
            GroceryItem eggs   = new GroceryItem("Eggs");
            GroceryItem cream  = new GroceryItem("Cream");
            GroceryItem yogurt = new GroceryItem("Yogurt");

            List <GroceryItem> itemList = new List <GroceryItem>();

            itemList.Add(milk);
            itemList.Add(butter);
            itemList.Add(eggs);
            itemList.Add(cream);
            itemList.Add(yogurt);


            Category dairy = new Category("Dairy", itemList);


            Form1 f = new Form1(dairy);

            f.Show();
            this.Hide();
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            this.SetContentView(Resource.Layout.GroceryEdit);

            //Pull out all of the "extras" that were passed in the intent
            _groceryItem = new GroceryItem()
            {
                ObjectId    = Intent.GetStringExtra("objectId"),
                Title       = Intent.GetStringExtra("title"),
                Description = Intent.GetStringExtra("description"),
                Quantity    = Intent.GetIntExtra("quantity", 0)
            };

            //Grab each of the text views, which display the details about the grocery item, and assign them values
            txtTitle      = FindViewById <EditText> (Resource.Id.editText1);
            txtTitle.Text = _groceryItem.Title;

            txtDescription      = FindViewById <EditText> (Resource.Id.editText2);
            txtDescription.Text = _groceryItem.Description;

            //Grab the spinner control, and bind it to the resource array
            Spinner spinner = FindViewById <Spinner> (Resource.Id.spinner1);

            spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs> (spinner_ItemSelected);

            var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.quantity_array, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = adapter;

            //Set the selected item - this is easy because we have a 0-based array, which matchs the quantity
            spinner.SetSelection(_groceryItem.Quantity);

            //Finally, wire up the "Save" button
            Button btnEdit = FindViewById <Button> (Resource.Id.btnEdit);

            btnEdit.Click += (object sender, EventArgs e) => {
                //Persist these changes somewhere, and then navigate back to the "Grocery Detail" view
                Toast.MakeText(this, "Saving...", ToastLength.Long).Show();

                _groceryItem.Title       = txtTitle.Text;
                _groceryItem.Description = txtDescription.Text;

                Task.Factory.StartNew(() => {
                    if (!string.IsNullOrEmpty(_groceryItem.ObjectId))
                    {
                        GroceryService.UpdateGroceryItem(_groceryItem);
                    }
                    else
                    {
                        GroceryService.CreateGroceryItem(_groceryItem);
                    }
                }).ContinueWith((prevTask) => {
                    Intent i = new Intent(this, typeof(GroceryList));
                    StartActivity(i);
                }, TaskScheduler.FromCurrentSynchronizationContext());
            };
        }
Beispiel #16
0
        private void produceButton_Click(object sender, EventArgs e)
        {
            GroceryItem apple   = new GroceryItem("Appple");
            GroceryItem brocoli = new GroceryItem("Brocoli");
            GroceryItem potato  = new GroceryItem("Potato");
            GroceryItem pear    = new GroceryItem("Pear");
            GroceryItem corn    = new GroceryItem("Corn");

            List <GroceryItem> itemList = new List <GroceryItem>();

            itemList.Add(apple);
            itemList.Add(brocoli);
            itemList.Add(potato);
            itemList.Add(pear);
            itemList.Add(corn);


            Category produce = new Category("Produce", itemList);


            Form1 f = new Form1(produce);

            f.Show();
            this.Hide();
        }
        public IHttpActionResult PutGroceryItem(int id, GroceryItem groceryItem)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            if (id != groceryItem.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #18
0
        private void packagedButton_Click(object sender, EventArgs e)
        {
            GroceryItem cereal      = new GroceryItem("Cereal");
            GroceryItem chips       = new GroceryItem("Chips");
            GroceryItem crackers    = new GroceryItem("Crackers");
            GroceryItem popcorn     = new GroceryItem("Popcorn");
            GroceryItem fruitsnacks = new GroceryItem("Fruit Snacks");

            List <GroceryItem> itemList = new List <GroceryItem>();

            itemList.Add(cereal);
            itemList.Add(chips);
            itemList.Add(crackers);
            itemList.Add(popcorn);
            itemList.Add(fruitsnacks);


            Category packaged = new Category("Packaged", itemList);


            Form1 f = new Form1(packaged);

            f.Show();
            this.Hide();
        }
Beispiel #19
0
        // PUT api/GroceryItem/5
        public IHttpActionResult PutGroceryItem(GroceryItem groceryitem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //if (id != groceryitem.GroceryItemId)
            //{
            //    return BadRequest();
            //}

            groceryitem.UpdatedDate     = DateTime.Now;
            db.Entry(groceryitem).State = System.Data.Entity.EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroceryItemExists(groceryitem.GroceryItemId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public static async Task UpdateItem(GroceryItem groceryItem)
 {
     var firebase = Authenticate();
     await firebase
     .Child("GroceryList")
     .Child(groceryItem.Name)
     .PutAsync(groceryItem);
 }
Beispiel #21
0
        private void RemoveItem(GroceryItem item)
        {
            ItemRemovedEvent e = new ItemRemovedEvent();

            e.Id = item.Id;

            _eventAggregator.Publish(e);
        }
 public EditPantryItemViewModel(GroceryItem item, IEnumerable <GroceryItemLocation> locations) : base(locations)
 {
     // Use Cheese object to initialize the ViewModel properties
     PantryId              = item.ID;
     Name                  = item.Name;
     GroceryNote           = item.GroceryNote;
     GroceryItemLocationID = item.LocationID;
 }
 public IActionResult Create(GroceryItem groceryItem)
 {
     groceryItem.OwnerEmail = this.User.Identity.Name;
     
     var newGroceryItem =  _groceryItem.CreateGroceryItem(groceryItem);
     newGroceryItem.OwnerEmail = this.User.Identity.Name;
     return Json(new { newGroceryItem.Id });
 }
Beispiel #24
0
    private static void Main()
    {
        var gi = new GroceryItem("Carrot");

        gi.Foo();

        Console.WriteLine(gi.Description);
    }
        /// <summary>
        /// SCREEN: add a character
        /// </summary>
        static void DisplayAddCharacter()
        {
            FlintstoneCharacter character = new FlintstoneCharacter();

            DisplayScreenHeader("Add a New Character");

            Console.Write("First Name:");
            character.FirstName = Console.ReadLine();

            Console.Write("Last Name:");
            character.LastName = Console.ReadLine();

            GetInteger("Age:", 1, 200, out int age);
            character.Age = age;

            Console.Write("Gender:");
            Enum.TryParse(Console.ReadLine(), out FlintstoneCharacter.GenderType gender);
            character.Gender = gender;

            Console.Write("Image File:");
            character.ImageFileName = Console.ReadLine();

            GetInteger("Gross Salary:", 1, 1000000, out int grossSalary);
            character.Age = grossSalary;

            Console.Write("Description:");
            character.Description = Console.ReadLine();

            character.GroceryList = new List <GroceryItem>();
            GetInteger("Number of Grocery Items:", 1, 20, out int numberOfGroceryItems);
            for (int i = 0; i < numberOfGroceryItems; i++)
            {
                GroceryItem groceryItem = new GroceryItem();

                Console.Write("Grocery Item Name:");
                groceryItem.Name = Console.ReadLine();

                GetInteger("Grocery Item Quantity:", 1, 200, out int quantity);
                groceryItem.Quantity = quantity;

                character.GroceryList.Add(groceryItem);
            }

            _fcBusiness.AddFlintstoneCharacter(character);

            if (_fcBusiness.FileIoStatus == FileIoMessage.Complete)
            {
                Console.WriteLine();
                Console.WriteLine($"{character.FirstName} {character.LastName} added successfully");
            }
            else
            {
                // process file IO error message
            }

            DisplayMainMenuPrompt();
        }
 public IActionResult Create(GroceryItem groceryItem)
 {
     if (ModelState.IsValid == true)
     {
         _databaseContext.AddGroceryItem(groceryItem);
         return(RedirectToAction("Index"));
     }
     return(View(groceryItem));
 }
    public void AddItem(GroceryItem item)
    {
        if (Items == null)
        {
            throw new InvalidOperationException("Cannot add item to null list");
        }

        Items.Add(item);
    }
        public async Task <ActionResult <GroceryItem> > PostGroceryItem(GroceryItem groceryItem)
        {
            groceryItem.Updated       = DateTime.UtcNow;
            groceryItem.AlreadyPicked = false;
            _context.groceryItems.Add(groceryItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetGroceryItem), new { id = groceryItem.Id }, groceryItem));
        }
Beispiel #29
0
        private void ChangeItemIsInCart(GroceryItem item)
        {
            ItemIsInCartChangedEvent e = new ItemIsInCartChangedEvent();

            e.Id       = item.Id;
            e.IsInCart = !item.IsInCart;

            _eventAggregator.Publish(e);
        }
        public void InsertGroceryItem([FromBody] GroceryItem ApiRequest)
        {
            // Null or Empty checks
            ApiRequest = ApiRequest ?? throw new NullReferenceException("Item object is null");

            // Creates an item or updates an existing item's quantity
            _groceryService.InsertGroceryItem(ApiRequest.name);

            _groceryService.UpdateGroceryItem(ApiRequest);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="groceryItem">The <see cref="GroceryItem"/> for which the promotion isvalid</param>
 /// <param name="quantity">The quantity of item which qualifies for the promotion</param>
 /// <param name="rate">The percentage of the item price to be computed</param>
 public RelativePricePromotion(GroceryItem groceryItem, int quantity, decimal rate)
 {
     Quantity = quantity;
     _rate = rate;
     Item = groceryItem;
 }