/// <summary>
        /// Returns the product in Json Format with specific Name
        /// </summary>
        /// <param name="productName">Name of the product</param>
        /// <returns></returns>
        public static string GetProductByName(string productName)
        {
            using (var db = new EHandel())
            {
                var query = (from p in db.Product
                             select new
                {
                    p.productId,
                    p.name,
                    p.description,
                    price = WithVAT ? p.price * VAT : p.price,
                    //p.price,
                    p.stock,
                    p.date,
                    p.isHidden
                }).AsEnumerable()
                            .Select(x => new Product()
                {
                    productId   = x.productId,
                    name        = x.name,
                    description = x.description,
                    price       = x.price,
                    stock       = x.stock,
                    date        = x.date,
                    isHidden    = x.isHidden
                }).ToList();

                return(ObjTooJson.ObjToJson(query));
            }
        }
        /// <summary>
        /// Returns the USER if login is correct (email/password)
        /// </summary>
        /// <param name="email">Email of customer</param>
        /// <param name="password">Password of customer</param>
        /// <returns></returns>
        public static string ValidateLogin(string email, string password)
        {
            using (var db = new EHandel())
            {
                var query = db.Customer
                            .FirstOrDefault(c => c.email == email && c.password == password);

                //var query = from u in db.Customer
                //            where u.email == email &&
                //                  u.password == password
                //            select new
                //            {
                //                u.isAdmin,
                //                u.userId,
                //                u.email,
                //                u.firstname,
                //                u.lastname,
                //                u.Address
                //            };

                return(ObjTooJson.ObjToJson(new List <Customer> {
                    query
                }));
            }
        }
        /// <summary>
        /// Returns ALL Catagory NAMES
        /// </summary>
        /// <returns></returns>
        public static string GetAllCategoryNames()
        {
            using (var db = new EHandel())
            {
                var query = from b in db.Category
                            select b.name;

                return(ObjTooJson.ObjToJson(query));
            }
        }
 public static string GetAllOrders()
 {
     using (var db = new EHandel())
     {
         var query = from o in db.Orders
                     select new
         {
             o.orderId,
             o.date,
             o.status,
             o.userId,
         };
         return(ObjTooJson.ObjToJson(query));
     }
 }
 /// <summary>
 /// returns all order by CUSTOMER ID
 /// </summary>
 /// <param name="userID">ID of CUSTOMER to get orders</param>
 /// <returns></returns>
 public static string GetAllOdersByCustomerID(int userID)
 {
     using (var db = new EHandel())
     {
         var query = from o in db.Orders
                     where o.userId == userID
                     select new
         {
             o.orderId,
             o.date,
             o.status
         };
         return(ObjTooJson.ObjToJson(query.ToList()));
     }
 }
 public static string GetAllCustomers()
 {
     using (var db = new EHandel())
     {
         var query = from c in db.Customer
                     select new
         {
             c.userId,
             c.email,
             c.firstname,
             c.lastname,
             c.isAdmin,
             c.password,
         };
         return(ObjTooJson.ObjToJson(query));
     }
 }
 /// <summary>
 /// Returns order by order id
 /// </summary>
 /// <param name="orderID">ID of the order</param>
 /// <returns></returns>
 public static string GetOrderByID(int orderID)
 {
     using (var db = new EHandel())
     {
         var query = from p in db.Product
                     join obp in db.OrdersByProduct on p.productId equals obp.productId
                     where obp.orderId == orderID
                     select new
         {
             p.productId,
             p.name,
             obp.count,
             price = WithVAT ? obp.price * VAT: obp.price
         };
         return(ObjTooJson.ObjToJson(query.ToList()));
     }
 }
 /// <summary>
 /// Returns ALL products as JSON
 /// </summary>
 /// <returns></returns>
 public static string GetAllProducts()
 {
     using (var db = new EHandel())
     {
         var query = from p in db.Product
                     select new
         {
             p.productId,
             p.name,
             p.description,
             price = WithVAT ? p.price * VAT : p.price,
             //p.price,
             p.stock,
             p.date
         };
         return(ObjTooJson.ObjToJson(query));
     }
 }
        public static string GetAdressByUserId(int userId)
        {
            using (var db = new EHandel())
            {
                var query = from a in db.Address
                            where a.userId == userId
                            select new
                {
                    a.addressId,
                    a.street,
                    a.zip,
                    a.city,
                    a.country,
                    a.userId,
                };

                return(ObjTooJson.ObjToJson(query));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns specific product in Json Format with specific ID
        /// </summary>
        /// <param name="productID">Name of the product</param>
        /// <returns></returns>
        public static string GetProductByID(int productID)
        {
            using (var db = new EHandel())
            {
                //Product prod = db.Product.FirstOrDefault(p => p.productId == productID);
                var query = from p in db.Product
                            where p.productId == productID
                            select new
                {
                    p.productId,
                    p.name,
                    p.description,
                    price = WithVAT ? p.price * VAT : p.price,
                    //p.price,
                    p.stock,
                    p.date
                };

                return(ObjTooJson.ObjToJson(query));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Returns ALL products from specific CATEGORY
        /// </summary>
        /// <param name="categoryID">CategoryID to get products from</param>
        /// <returns></returns>
        public static string GetAllProductsFromCategory(int categoryID)
        {
            using (var db = new EHandel())
            {
                var query = from p in db.Product
                            join ctp in db.CategoryToProduct on p.productId equals ctp.productId
                            join c in db.Category on ctp.categoryId equals c.categoryId
                            where c.categoryId == categoryID
                            select new
                {
                    p.productId,
                    p.name,
                    p.description,
                    price = WithVAT ? p.price * VAT : p.price,
                    //p.price,
                    p.stock,
                    p.date
                };

                return(ObjTooJson.ObjToJson(query.ToList()));
            }
        }