Esempio n. 1
0
    public static void Main()
    {
        string choice;

        Console.WriteLine("What would you like to order? 1-Grocery Items, 2- Bakery Products");
        choice = Console.ReadLine();
        if (choice == "1")
        {
            GroceryItems grocery = new GroceryItems();
            grocery.Ord_grocery();
        }
        else
        {
            if (choice == "2")
            {
                BakeryProducts bakery = new BakeryProducts();
                bakery.Ord_bakery();
            }
            else
            {
                Console.WriteLine("Enter either 1 or 2");
            }
        }
        Console.ReadLine();
    }
Esempio n. 2
0
        public static void addGroceryItem(GroceryItems g)
        {
            SqlConnection connection = FamilyDB.getConnection();

            String     query = "Insert into ListItems (familyID, listItem, listType, storeName, salePrice, isComplete) values (@familyID, @listItem, @listType, @storeName, @salePrice, @isComplete)";
            SqlCommand cmd   = new SqlCommand(query, connection);

            cmd.Parameters.AddWithValue("@familyID", g.FamilyID);
            cmd.Parameters.AddWithValue("@listItem", g.ListItem);
            cmd.Parameters.AddWithValue("@listType", g.ListType);
            cmd.Parameters.AddWithValue("@storeName", g.StoreName);
            cmd.Parameters.AddWithValue("@salePrice", g.StorePrice);
            cmd.Parameters.AddWithValue("@isComplete", g.IsComplete);

            try
            {
                if (connection != null)
                {
                    connection.Open();
                }
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                connection.Close();
            }
        }
Esempio n. 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            GroceryItems groceryItems = db.GroceryItems.Find(id);

            db.GroceryItems.Remove(groceryItems);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        public static List <GroceryItems> getGroceryList(int famID)
        {
            if (famID == null)
            {
                return(null);
            }

            List <GroceryItems> allGrocery = new List <GroceryItems>();

            SqlConnection connection = FamilyDB.getConnection();

            if (connection != null)
            {
                connection.Open();
            }
            string listType = "grocery";

            String     query = "SELECT listItem, storeName, salePrice FROM ListItems WHERE familyID = @famID and listType = @listType";
            SqlCommand cmd   = new SqlCommand(query, connection);

            cmd.Parameters.AddWithValue("@famID", famID);
            cmd.Parameters.AddWithValue("@listType", listType);


            try
            {
                SqlDataReader read = cmd.ExecuteReader();

                if (read.Read())
                {
                    GroceryItems g = new GroceryItems();
                    g.ListItem   = (string)read["listItem"];
                    g.StoreName  = (string)read["storeName"];
                    g.StorePrice = (double)read["storePrice"];

                    allGrocery.Add(g);
                }
                else
                {
                    return(null);
                }
            }
            catch (SqlException ex)
            {
                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                connection.Close();
            }
            return(allGrocery);
        }
Esempio n. 5
0
 public ActionResult Edit([Bind(Include = "Id,Item,Amount,Price")] GroceryItems groceryItems)
 {
     if (ModelState.IsValid)
     {
         db.Entry(groceryItems).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(groceryItems));
 }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "Id,Item,Amount,Price")] GroceryItems groceryItems)
        {
            if (ModelState.IsValid)
            {
                db.GroceryItems.Add(groceryItems);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(groceryItems));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("ItemId,ProductId,RealCost")] GroceryItems groceryItems)
        {
            if (ModelState.IsValid)
            {
                _context.Add(groceryItems);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(groceryItems));
        }
Esempio n. 8
0
        // GET: GroceryItems/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroceryItems groceryItems = db.GroceryItems.Find(id);

            if (groceryItems == null)
            {
                return(HttpNotFound());
            }
            return(View(groceryItems));
        }
Esempio n. 9
0
        public async Task SaveGroceryItemAsync(GroceryItems item)
        {
            var uri     = new Uri(url);
            var json    = JsonConvert.SerializeObject(item);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage response = null;

            response = await client.PostAsync(uri, content);

            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine(@"TodoItem successfully saved.");
            }
        }
Esempio n. 10
0
        private async void Save_OnClicked(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(Item.Text))
            {
                await DisplayAlert("Required", "Please add an item", "Ok");

                return;
            }

            GroceryItems groceryItem = new GroceryItems();

            groceryItem.GroceryItem = Item.Text;

            await service.SaveGroceryItemAsync(groceryItem);

            LoadGroceryList();
            Item.Text = string.Empty;
            Item.Unfocus();
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            CostomerName   name   = new CostomerName();
            GroceryItems   item   = new GroceryItems();
            BakeryProducts bakery = new BakeryProducts();
            int            n      = 0;

            name.ReadName();
            do
            {
                Console.Write("Orders: \n" +
                              "1. Grocery Items \n" +
                              "2. Bakery Products \n" +
                              "Choose: ");
                n = Convert.ToInt32(Console.ReadLine());
                while (n < 0 || n > 2)
                {
                    Console.Write("Order: \n" +
                                  "1. Grocery Items \n" +
                                  "2. Bakery Products \n" +
                                  "Choose: ");
                    n = Convert.ToInt32(Console.ReadLine());
                }
                switch (n)
                {
                case 1:

                    item.Items();

                    break;

                case 2:
                    bakery.Bakery();
                    break;
                }
            }while (n != 0);
            Console.WriteLine("------------- \n" + name.getName());
            item.ReadItems();
            bakery.ReadBakery();
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            int          familyID = (int)Session["familyID"];
            GroceryItems g        = new GroceryItems();

            g.FamilyID   = familyID;
            g.ListItem   = txtItem.Text;
            g.StoreName  = txtStore.Text;
            g.StorePrice = Convert.ToDouble(txtPrice.Text);
            g.IsComplete = "N";
            g.ListType   = "grocery";
            try
            {
                ListDA.addGroceryItem(g);
                lblError.Text = "List item added Successfully";
                Response.Redirect("~/Views/GroceryList.aspx");
            }
            catch
            {
                lblError.Text = "There was an error adding the list item";
                Response.Redirect("~/Views/GroceryList.aspx");
            }
        }
Esempio n. 13
0
        public async Task <IActionResult> Edit(int id, [Bind("City,Date,Price,ItemId,Title,Quantity,GroceryListId")] GroceryItems groceryItems)  /*Or Try Passing in ListIdItemId,ProductId,RealCost*/
        {
            TempData["ListId"] = groceryItems.GroceryListId;
            if (id != groceryItems.ItemId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.GroceryItems.Update(groceryItems);
                    //_context.Update(groceryItems.ItemId);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GroceryItemsExists(groceryItems.ItemId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction(nameof(ItemsInList));
                int listId = Convert.ToInt32(TempData["ListId"].ToString());
                return(RedirectToAction("ItemsInList", new { id = listId }));
                // // // // // // // // // // Figuring out how to pass in the correct Id
            }
            int listId2 = Convert.ToInt32(TempData["ListId"].ToString());

            return(RedirectToAction("ItemsInList", new { id = listId2 }));
        }
 public List <GroceryItem> GetAllGroceryItems()
 {
     return(GroceryItems
            .Include(groceryItem => groceryItem.Store)
            .ToList());
 }
 public void AddGroceryItem(GroceryItem groceryItem)
 {
     GroceryItems.Add(groceryItem);
     SaveChanges();
 }