Ejemplo n.º 1
0
        public void FindItem3()
        {
            List <MenuItemPrice> MenuItemPrices = new List <MenuItemPrice>();

            using (SqlConnection connection = new SqlConnection("Server=tcp:sqlweek1-elijah.database.windows.net,1433;Initial Catalog=pizzzaDatabase;Persist Security Info=False;User ID=sqladmin_elijah;Password=8Vdh17boc8@;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"))
                using (SqlCommand cmd = new SqlCommand("SELECT * from MenuItemPrice", connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        // Check is the reader has any rows at all before starting to read.
                        if (reader.HasRows)
                        {
                            // Read advances to the next row.
                            while (reader.Read())
                            {
                                MenuItemPrice MIP = new MenuItemPrice();
                                // To avoid unexpected bugs access columns by name.
                                MIP.Id     = reader.GetInt32(reader.GetOrdinal("ID"));
                                MIP.MenuId = reader.GetInt32(reader.GetOrdinal("MenuID"));
                                MIP.SizeId = reader.GetInt32(reader.GetOrdinal("SizeID"));
                                // int middleNameIndex = reader.GetOrdinal("MiddleName");
                                // If a column is nullable always check for DBNull...

                                MenuItemPrices.Add(MIP);
                            }

                            foreach (var item in MenuItemPrices)
                            {
                                Console.WriteLine(item);
                            }
                        }
                    }
                }
        }
Ejemplo n.º 2
0
        public void AddPrice(string tag)
        {
            var pr = new MenuItemPrice {
                PriceTag = tag
            };

            Model.Prices.Add(pr);
            AdditionalPrices.Add(new MenuItemPriceViewModel(pr));
        }
        public IHttpActionResult PostMenuItemPrice(MenuItemPrice menuItemPrice)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.MenuItemPrices.Add(menuItemPrice);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = menuItemPrice.ID }, menuItemPrice));
        }
        public IHttpActionResult PutMenuItemPrice(int id, MenuItemPrice menuItemPrice)
        {
            if (!Global.CheckUserIDAndPasswordWithSiteID(db, menuItemPrice.UILoginUserID, menuItemPrice.UILoginPassword, menuItemPrice.SiteID, "PutMenuItemPrice"))
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            MenuItemPrice mip = db.MenuItemPrices.AsNoTracking().SingleOrDefault(p => p.ID == id);

            if (mip == null)
            {
                return(NotFound());
            }
            if (mip.SiteID != menuItemPrice.SiteID)
            {
                return(BadRequest());
            }
            User user = db.Users.Find(menuItemPrice.UILoginUserID);

            if (!user.IsRootUser && !user.IsSiteAdmin && mip.EntryByUserID != user.ID)
            {
                return(BadRequest());
            }
            db.Entry(menuItemPrice).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult DeleteMenuItemPrice(int id)
        {
            MenuItemPrice menuItemPrice = db.MenuItemPrices.Find(id);

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

            db.MenuItemPrices.Remove(menuItemPrice);
            db.SaveChanges();

            return(Ok(menuItemPrice));
        }
Ejemplo n.º 6
0
 public void Post([FromBody] Item newMenuItem)
 {
     try
     {
         MenuItemPrice addMenuItem = new MenuItemPrice
         {
             MenuId = _context.MenuItem.Single(z => z.Item == newMenuItem.ItemName).MenuId,
             SizeId = _context.ItemSize.FirstOrDefault(z => z.Size == newMenuItem.ItemSize).SizeId,
             Price  = newMenuItem.ItemPrice
         };
         _context.MenuItemPrice.Add(addMenuItem);
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 7
0
 public MenuItemPriceViewModel(MenuItemPrice model)
 {
     Model = model;
 }