Ejemplo n.º 1
0
      public string GetCartItem(int id)
      {
          using (DinerAppDB2Entities db = new DinerAppDB2Entities())
          {
              CartDTO item = (from listitem in db.Carts
                              //join m in db.Menus on id equals m.menu_id into members
                              where id == listitem.menu_id
                              select new CartDTO()
                {
                    id = listitem.cart_id,
                    menu_id = listitem.menu_id,
                    name = listitem.Menu.name,
                    price = listitem.Menu.price,
                    quantity = listitem.quantity
                }).Single();
              if (item == null)
              {
                  return("Not Found");
              }

              var json = JsonConvert.SerializeObject(item);

              return(json);
          }
      }
Ejemplo n.º 2
0
        public string GetUser(string name)
        {
            using (DinerAppDB2Entities db = new DinerAppDB2Entities())
            {
                try
                {
                    var user = (from item in db.Users
                                where name == item.username
                                select new UserDTO()
                    {
                        username = item.username,
                        password = item.password,
                        fname = item.fname,
                        lname = item.lname,
                        street = item.street,
                        city = item.city,
                        state = item.state,
                        zip = item.zipcode
                    }).Single();

                    // UserDTO userDTO = DTOMapper.UserConvertToDTO(user);

                    var json = JsonConvert.SerializeObject(user);

                    return(json);
                }
                catch (ArgumentNullException e)
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 3
0
      public decimal?GetTotal()
      {
          using (DinerAppDB2Entities db = new DinerAppDB2Entities())
          {
              var total = db.GetTotal().Single();

              /*IEnumerable<CartDTO> cartDTO = (from item in db.Carts
               *                                  //join m in db.Menus on item.menu_id equals m.menu_id into members
               *                              where item.Menu.menu_id == item.menu_id
               *                              select new CartDTO()
               *                              {
               *                                  id = item.cart_id,
               *                                  menu_id = item.menu_id,
               *                                  name = item.Menu.name,
               *                                  price = item.Menu.price,
               *                                  quantity = item.quantity
               *                              }).ToList();*/


              //IEnumerable<CartDTO> cartDTO = DTOMapper.CartConvertToDTO(cart);


              return(total);
          }
      }
Ejemplo n.º 4
0
        public IHttpActionResult PostAddItem([FromBody] string data)
        {
            using (DinerAppDB2Entities db = new DinerAppDB2Entities())
            {
                //Menu cart = new Menu();
                Menu menu = JsonConvert.DeserializeObject <Menu>(data);

                bool Exist = false;

                Exist = db.Menus.Any(r => r.menu_id.Equals(menu.menu_id));

                if (Exist)
                {
                    return(null);
                }

                if (Exist == false)
                {
                    db.Menus.Add(menu);
                    db.SaveChanges();
                    return(Ok(menu));
                }
                return(Ok());
            }
        }
Ejemplo n.º 5
0
        public string GetMenu()
        {
            using (DinerAppDB2Entities db = new DinerAppDB2Entities())
            {
                List <Menu> menu = new List <Menu>();

                menu = (from item in db.Menus
                        select item).ToList();

                IEnumerable <MenuDTO> menuDTO = DTOMapper.MenuConvertToDTO(menu);

                string json = JsonConvert.SerializeObject(menuDTO);

                return(json);
            }
        }
Ejemplo n.º 6
0
      //[Route("api/AddItem")]
      public IHttpActionResult PostAddItem([FromBody] string data)
      {
          using (DinerAppDB2Entities db = new DinerAppDB2Entities())
          {
              Cart    cart = new Cart();
              CartDTO C    = JsonConvert.DeserializeObject <CartDTO>(data);
              //gets menu_id from Menu
              var menu_id = (from item in db.Menus
                             where C.name == item.name
                             select item.menu_id).SingleOrDefault();

              bool Exist = false;

              Exist = db.Carts.Any(r => r.menu_id.Equals(menu_id));

              if (Exist)
              {
                  var row = (from item in db.Carts
                             where menu_id == item.menu_id
                             select item).Single();


                  row.quantity += C.quantity;
                  if (row.quantity > 20)
                  {
                      row.quantity = 20;
                  }
                  db.SaveChanges();
                  return(Ok(row.quantity));
              }


              if (Exist == false)
              {
                  cart = new Cart()
                  {
                      menu_id  = menu_id,
                      quantity = C.quantity
                  };

                  db.Carts.Add(cart);
                  db.SaveChanges();
                  return(Ok(cart));
              }
              return(Ok());
          }
      }
Ejemplo n.º 7
0
 public IHttpActionResult DeleteMenuItemAtIndex(int index)
 {
     using (DinerAppDB2Entities db = new DinerAppDB2Entities())
     {
         try
         {
             // Menu.menu.RemoveAt(index);
         }
         catch (ArgumentOutOfRangeException e)
         {
             //log the exception e.Message
             return(BadRequest("The index is out of range"));
         }
         return(null);
         //return Ok(Menu.menu);
     }
 }
Ejemplo n.º 8
0
        public string AuthenticateUser(string username, string password)
        {
            using (DinerAppDB2Entities db = new DinerAppDB2Entities())
            {
                try
                {
                    var user = (from item in db.Users
                                where username == item.username && password == item.password
                                select item).SingleOrDefault();


                    if (user == null)
                    {
                        return(null);
                    }

                    /*new UserDTO()
                     * {
                     *  username = item.username,
                     *  password = item.password,
                     *  fname = item.fname,
                     *  lname = item.lname,
                     *  street = item.street,
                     *  city = item.city,
                     *  state = item.state,
                     *  zip = item.zipcode
                     * }).Single();*/

                    UserDTO userDTO = DTOMapper.UserConvertToDTO(user);


                    var json = JsonConvert.SerializeObject(userDTO);

                    return(json);
                }
                catch (ArgumentNullException e)
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 9
0
      // [Route("api/Cart/{name}")]
      public IHttpActionResult UpdateCartItem([FromBody] string data)
      {
          using (DinerAppDB2Entities db = new DinerAppDB2Entities())
          {
              var cart = JObject.Parse(data);
              var name = (string)cart["name"];
              //gets the record that needs to be updated
              var item = (from listitem in db.Carts
                          //join m in db.Menus on id equals m.menu_id into members
                          where name == listitem.Menu.name
                          select listitem).Single();

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

              item.quantity = (int)cart["quantity"];
              db.SaveChanges();
              return(Ok(item.quantity));
          }
      }
Ejemplo n.º 10
0
      public IHttpActionResult DeleteCartItemByID(string name)
      {
          using (DinerAppDB2Entities db = new DinerAppDB2Entities())
          {
              try
              {
                  var row = (from item in db.Carts
                             where name == item.Menu.name
                             select item).Single();


                  db.Carts.Remove(row);
                  db.SaveChanges();
                  return(Ok(row));
              }
              catch (ArgumentOutOfRangeException e)
              {
                  //log the exception e.Message
                  return(BadRequest("The item is not in the Cart"));
              }
          }
      }
Ejemplo n.º 11
0
        public string GetMenuItem(string name)
        {
            using (DinerAppDB2Entities db = new DinerAppDB2Entities())
            {
                MenuDTO item = (from listitem in db.Menus
                                where name == listitem.name
                                select new MenuDTO()
                {
                    name = listitem.name,
                    price = listitem.price,
                    cat = listitem.cat_id
                }).Single();

                if (item == null)
                {
                    return("Not Found");
                }

                var json = JsonConvert.SerializeObject(item);

                return(json);
            }
        }
Ejemplo n.º 12
0
        // [Route("api/Cart/{name}")]
        public IHttpActionResult UpdateMenuItem([FromBody] string data)
        {
            using (DinerAppDB2Entities db = new DinerAppDB2Entities())
            {
                Menu menu = JsonConvert.DeserializeObject <Menu>(data);

                //gets the record that needs to be updated
                var item = (from listitem in db.Menus
                            //join m in db.Menus on id equals m.menu_id into members
                            where menu.name == listitem.name
                            select listitem).Single();

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

                item.cat_id = menu.cat_id;
                item.price  = menu.price;
                db.SaveChanges();
                return(Ok(menu));
            }
        }
Ejemplo n.º 13
0
      public string GetCart()
      {
          using (DinerAppDB2Entities db = new DinerAppDB2Entities())
          {
              IEnumerable <CartDTO> cartDTO = (from item in db.Carts
                                               //join m in db.Menus on item.menu_id equals m.menu_id into members
                                               where item.Menu.menu_id == item.menu_id
                                               select new CartDTO()
                {
                    id = item.cart_id,
                    menu_id = item.menu_id,
                    name = item.Menu.name,
                    price = item.Menu.price,
                    quantity = item.quantity
                }).ToList();


              //IEnumerable<CartDTO> cartDTO = DTOMapper.CartConvertToDTO(cart);

              var json = JsonConvert.SerializeObject(cartDTO);

              return(json);
          }
      }