public IHttpActionResult LoginVendor([FromBody] Vendor venderDetails)
        {
            var email = venderDetails.VendorEmailId;
            var pass  = venderDetails.VendorPassword;

            if (email == null || pass == null || email == "" || pass == "")
            {
                return(BadRequest("BadRequest"));
            }

            MyFoodiesEntities ent;

            try
            {
                ent = new MyFoodiesEntities();
                var data = ent.Vendors.Where(x => x.VendorEmailId == email && x.VendorPassword == pass).
                           Select(x => new { x.VendorEmailId, x.VendorId }).FirstOrDefault();

                return(Ok(data));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
        [HttpPut] //api/Customer/CustomerId
        public IHttpActionResult UpdateCustomer([FromUri] int id, [FromBody] Customer updated)
        {
            MyFoodiesEntities ent;

            try
            {
                if (id == updated.CustomerId)
                {
                    ent = new MyFoodiesEntities();
                    Customer c = ent.Customers.Find(id);
                    c.CustomerName     = updated.CustomerName;
                    c.CustomerMobileNo = updated.CustomerMobileNo;
                    c.CustomerAddress  = updated.CustomerAddress;
                    c.CustomerLocation = updated.CustomerLocation;
                    ent.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception)
            {
                return(InternalServerError());
            }

            return(Ok(new { Name = updated.CustomerName, Email = updated.CustomerEmailId }));
        }
        public IHttpActionResult GetMyOrders([FromUri] int id)
        {
            MyFoodiesEntities ent       = new MyFoodiesEntities();
            List <Order>      orders    = ent.Orders.Where(x => x.VendorId == id).ToList();
            List <Customer>   customers = ent.Customers.ToList();
            List <FoodItem>   fooditems = ent.FoodItems.ToList();

            var myorders = from order in orders
                           join c in customers on order.CustomerId equals c.CustomerId into table1
                           from nt in table1.ToList()
                           join food in fooditems on order.FoodItemId equals food.FoodId into table2
                           from i in table2.ToList()
                           select new
            {
                order.OrderId,
                nt.CustomerName,
                nt.CustomerLocation,
                i.FoodName,
                i.FoodDetails,
                i.FoodRating,
                order.OrderQuantity,
                order.OrderAmount,
                order.OrderDate,
                order.OrderTime,
                order.OrderStatus,
                order.OrderLocation
            };

            return(Ok(myorders));
        }
        [HttpPut] //api/Vendor/VendorId
        public IHttpActionResult UpdateVendor([FromUri] int id, [FromBody] Vendor updated)
        {
            MyFoodiesEntities ent;

            try
            {
                if (id == updated.VendorId)
                {
                    ent = new MyFoodiesEntities();
                    Vendor v = ent.Vendors.Find(id);
                    v.VenderName     = updated.VenderName;
                    v.VendorLocation = updated.VendorLocation;
                    v.VendorAddress  = updated.VendorAddress;
                    v.VendorMobileNo = updated.VendorMobileNo;
                    v.RestaurantName = updated.RestaurantName;
                    ent.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception)
            {
                return(InternalServerError());
            }

            return(Ok(new { Name = updated.VenderName, Email = updated.VendorEmailId }));
        }
        public IHttpActionResult GetMenus([FromUri] int id)
        {
            MyFoodiesEntities ent = new MyFoodiesEntities();
            var vendorMenu        = ent.FoodItems.Where(x => x.VendorId == id).Select(x => new {
                x.FoodId,
                x.FoodName,
                x.FoodPrice,
                x.FoodDetails,
                x.FoodStatus,
                x.FoodRating
            }).ToList();

            return(Ok(vendorMenu));
        }
        [HttpPost] //api/Customer/
        public IHttpActionResult RegisterCustomer([FromBody] Customer user)
        {
            MyFoodiesEntities ent;

            try {
                ent = new MyFoodiesEntities();
                ent.Customers.Add(user);
                ent.SaveChanges();
            }
            catch (Exception)
            {
                return(InternalServerError());
            }

            return(Created("Created SuccessFully", new { Name = user.CustomerName, Email = user.CustomerEmailId }));
        }
        [HttpPost] //api/Vendor/
        public IHttpActionResult AddFoodItem([FromBody] FoodItem food)
        {
            MyFoodiesEntities ent;

            try
            {
                ent = new MyFoodiesEntities();
                ent.FoodItems.Add(food);
                ent.SaveChanges();
            }
            catch (Exception)
            {
                return(InternalServerError());
            }

            return(Created("Created SuccessFully", new { msg = "Food Added Successfully." }));
        }
        [HttpPost] //api/Customer/placeorder
        public IHttpActionResult PlaceCustomerOrder([FromBody] Order orderdata)
        {
            MyFoodiesEntities ent;

            try
            {
                ent = new MyFoodiesEntities();
                ent.Orders.Add(orderdata);
                ent.SaveChanges();
            }
            catch (Exception)
            {
                return(InternalServerError());
            }

            return(Created("Created SuccessFully", new { msg = "success" }));
        }
        public IHttpActionResult GetMenus()
        {
            MyFoodiesEntities ent = new MyFoodiesEntities();
            var vendors           = ent.Vendors;
            var food       = ent.FoodItems;
            var vendorMenu = vendors.Join(food, vend => vend.VendorId, fooditem => fooditem.VendorId,
                                          (vend, fooditem) => new {
                vend.VendorId,
                vend.RestaurantName,
                fooditem.FoodId,
                fooditem.FoodName,
                fooditem.FoodPrice,
                fooditem.FoodDetails,
                fooditem.FoodStatus,
                fooditem.FoodRating,
            }).ToList();

            return(Ok(vendorMenu));
        }
        [HttpGet]  //api/Customer/CustomerId
        public IHttpActionResult GetCustomerDetalilsByCustomerId(int id)
        {
            MyFoodiesEntities ent;

            try{
                ent = new MyFoodiesEntities();
                var cs = ent.Customers.Where(x => x.CustomerId == id).Select(x => new {
                    x.CustomerId,
                    x.CustomerName,
                    x.CustomerEmailId,
                    x.CustomerMobileNo,
                    x.CustomerAddress,
                    x.CustomerLocation
                }).FirstOrDefault();
                return(Ok(cs));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
Exemple #11
0
        [HttpDelete]//api/Vendor/Foodid
        public IHttpActionResult DeleteMenuItem([FromUri] int id)
        {
            MyFoodiesEntities ent = new MyFoodiesEntities();

            try
            {
                FoodItem food = ent.FoodItems.Find(id);

                if (food != null)
                {
                    ent.FoodItems.Remove(food);
                    ent.SaveChanges();
                    return(Ok(new { msg = "Deleted Successfully" }));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
Exemple #12
0
        [HttpPut] //api/Vendor/updateFood/foodid
        public IHttpActionResult UpdateMenuItem([FromUri] int id, [FromBody] FoodItem updated)
        {
            MyFoodiesEntities ent;

            try
            {
                if (id == updated.FoodId)
                {
                    ent = new MyFoodiesEntities();
                    ent.Entry(updated).State = System.Data.Entity.EntityState.Modified;
                    ent.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception)
            {
                return(InternalServerError());
            }

            return(Ok(new { FoodName = updated.FoodName }));
        }