public IHttpActionResult GetAllOrders()
        {
            var DB      = new AngularDemoEntities();
            var user_id = User.Identity.GetUserId();

            try
            {
                var O = DB.Order_Master.Select(x => new {
                    x.BankName,
                    x.BillingAddress,
                    x.ChequeNo,
                    x.City,
                    x.DeliveryDate,
                    x.Mobile,
                    x.Name,
                    x.OrderDate,
                    x.OrderID,
                    x.PaymentMethod,
                    x.ShippingAddress,
                    x.State,
                    x.States_Master.StateName,
                    x.City_Master.CityName,
                    x.UserID,
                    x.Zipcode,
                    x.TotalAmount
                }).ToList();
                return(Ok(O));
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
Exemple #2
0
 public IEnumerable <Employee> Get(int pageIndex = 1)
 {
     using (AngularDemoEntities entities = new AngularDemoEntities())
     {
         return(entities.Employees.Take(pageIndex * 2).ToList());
     }
 }
 public IHttpActionResult GetProByID(int ID)
 {
     try
     {
         var DB      = new AngularDemoEntities();
         var Product = DB.Product_Master.Where(x => x.ProductID == ID).Select(x => new
         {
             x.ProductID,
             x.CategoryID,
             x.Category_Master.CategoryName,
             x.ProductImage,
             x.ProductPrice,
             x.InStock,
             x.ProductQuantity,
             x.ProductName,
             x.ProductDescription
         }).FirstOrDefault();
         if (Product != null)
         {
             return(Ok(Product));
         }
         else
         {
             return(NotFound());
         }
     }
     catch (Exception ex)
     {
         throw ex.InnerException;
     }
 }
 public IHttpActionResult CartItems()
 {
     try
     {
         var user_id       = User.Identity.GetUserId();
         var DB            = new AngularDemoEntities();
         var Cart_products = DB.Cart_Master.Where(x => x.UserID == user_id).Select(y => new
         {
             y.CartID,
             y.ProductQuantity,
             y.ProductID,
             y.Product_Master.ProductName,
             y.Product_Master.ProductPrice,
             y.Product_Master.ProductImage,
             y.UserID,
             y.Product_Master.ProductDescription,
             y.Product_Master.InStock
         }).ToList();
         return(Ok(Cart_products));
     }
     catch (Exception ex)
     {
         throw ex.InnerException;
     }
 }
Exemple #5
0
        public Employee Get(string code)
        {
            int currentPageIndex = 1;

            int.TryParse(code, out currentPageIndex);
            using (AngularDemoEntities entities = new AngularDemoEntities())
            {
                return(entities.Employees.FirstOrDefault(emp => emp.Code.Equals(code)));
            }
        }
Exemple #6
0
        public IHttpActionResult GetEmployee()
        {
            IList <Employee_Master> employee = null;

            using (var DB = new AngularDemoEntities())
            {
                employee = DB.Employee_Master.ToList <Employee_Master>();
            }
            if (employee.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(employee));
        }
        public IHttpActionResult CheckIsProfile()
        {
            var DB      = new AngularDemoEntities();
            var user_id = User.Identity.GetUserId();

            try
            {
                bool IsProfile = DB.UserProfile_Master.Any(x => x.UserID == user_id);
                return(Ok(IsProfile));
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult CartItemTolal()
        {
            var DB = new AngularDemoEntities();

            try
            {
                var user_id        = User.Identity.GetUserId();
                int TotalCartItems = DB.Cart_Master.Where(x => x.UserID == user_id).Count();
                return(Ok(TotalCartItems));
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult GetCity(int ID)
        {
            var DB = new AngularDemoEntities();

            try
            {
                var City = DB.City_Master.Where(x => x.StateID == ID).OrderBy(x => x.CityName).Select(y => new
                {
                    y.CityID,
                    y.CityName
                }).ToList();
                return(Ok(City));
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult GetStates()
        {
            var DB = new AngularDemoEntities();

            try
            {
                var states = DB.States_Master.OrderBy(x => x.StateName).Select(y => new
                {
                    y.StateID,
                    y.StateName
                }).ToList();
                return(Ok(states));
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult UpdateQty(int ID, int Qty)
        {
            var user_id = User.Identity.GetUserId();
            var DB      = new AngularDemoEntities();

            try
            {
                var Cart_item = DB.Cart_Master.Where(x => x.CartID == ID).FirstOrDefault();
                if (Cart_item != null)
                {
                    var Product = DB.Product_Master.Where(x => x.ProductID == Cart_item.ProductID).FirstOrDefault();
                    if (Qty < Product.ProductQuantity)
                    {
                        if (Qty <= Product.ProductQuantity && Qty >= Cart_item.ProductQuantity)
                        {
                            Product.ProductQuantity   -= Math.Abs(Qty);
                            Cart_item.ProductQuantity += Math.Abs(Qty);
                            DB.SaveChanges();
                            return(Ok("success"));
                        }
                        else
                        {
                            Product.ProductQuantity   -= Qty;
                            Cart_item.ProductQuantity += Qty;
                            DB.SaveChanges();
                            return(Ok("success"));
                        }
                    }
                    else
                    {
                        return(Ok("OutOfStock"));
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult Checkout(Order_Master O)
        {
            var DB = new AngularDemoEntities();

            try
            {
                var user_id = User.Identity.GetUserId();
                O.OrderDate    = DateTime.Now;
                O.DeliveryDate = DateTime.Now.AddDays(5);
                O.UserID       = user_id;
                DB.Order_Master.Add(O);
                DB.SaveChanges();
                int InsertedOrderID  = O.OrderID;
                List <Cart_Master> C = DB.Cart_Master.Where(x => x.UserID == user_id).ToList();
                if (C.Count > 0)
                {
                    foreach (var i in C)
                    {
                        OrderItems_Master OI = new OrderItems_Master
                        {
                            OrderID   = InsertedOrderID,
                            ProductID = Convert.ToInt32(i.ProductID),
                            Quantity  = Convert.ToDecimal(i.ProductQuantity),
                            UserID    = i.UserID,
                            UnitPrice = Convert.ToDecimal(i.Product_Master.ProductPrice)
                        };
                        DB.OrderItems_Master.Add(OI);
                        DB.Cart_Master.Remove(i);
                        DB.SaveChanges();
                    }
                    return(Ok("success"));
                }
                else
                {
                    return(Ok("Some problem"));
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult GetRegisteredCustomers()
        {
            var DB = new AngularDemoEntities();

            try
            {
                var cust = DB.UserProfile_Master.Select(x => new {
                    x.City,
                    x.FirstName,
                    x.Gender,
                    x.LastName, x.Mobile, x.ProfilePicture, x.State, x.UserID, x.U_ID,
                    x.AspNetUser.Email, x.AspNetUser.Id, x.AspNetUser.UserName
                }).ToList();
                return(Ok(cust));
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
 public IHttpActionResult Category()
 {
     try
     {
         var DB       = new AngularDemoEntities();
         var Category = DB.Category_Master.Select(x => new
         {
             x.CategoryID,
             x.CategoryName
         }).ToList();
         if (Category.Count == 0)
         {
             return(NotFound());
         }
         return(Ok(Category));
     }
     catch (Exception ex)
     {
         throw ex.InnerException;
     }
 }
        public IHttpActionResult GetCurrentUser()
        {
            var DB      = new AngularDemoEntities();
            var user_id = User.Identity.GetUserId();

            try
            {
                var user = DB.UserProfile_Master.Where(x => x.UserID == user_id).FirstOrDefault();
                if (user != null)
                {
                    return(Ok(user));
                }
                else
                {
                    return(Ok("Not Found"));
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult AddProfile(Profile P)
        {
            var DB = new AngularDemoEntities();

            try
            {
                if (P != null)
                {
                    byte[] ImageFile = null;
                    if (!string.IsNullOrEmpty(P.ProfilePicture))
                    {
                        ImageFile = Convert.FromBase64String(P.ProfilePicture.Split(',')[1]);
                    }
                    var user_id           = User.Identity.GetUserId();
                    UserProfile_Master UP = new UserProfile_Master
                    {
                        UserID         = user_id,
                        FirstName      = P.FirstName,
                        City           = P.City,
                        Gender         = P.Gender,
                        LastName       = P.LastName,
                        Mobile         = P.Mobile,
                        ProfilePicture = ImageFile,
                        State          = P.State
                    };
                    DB.UserProfile_Master.Add(UP);
                    DB.SaveChanges();
                    return(Ok("success"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
 public IHttpActionResult DeleteProduct(int P_ID)
 {
     try
     {
         var DB      = new AngularDemoEntities();
         var Product = DB.Product_Master.Where(x => x.ProductID == P_ID).FirstOrDefault();
         if (Product != null)
         {
             DB.Product_Master.Remove(Product);
             DB.SaveChanges();
             return(Ok("success"));
         }
         else
         {
             return(Ok("Record not found"));
         }
     }
     catch (Exception ex)
     {
         throw ex.InnerException;
     }
 }
        public IHttpActionResult AddToCart(Cart_Master C)
        {
            var DB = new AngularDemoEntities();

            try
            {
                if (C != null)
                {
                    var  user_id = User.Identity.GetUserId();
                    bool IsThere = DB.Cart_Master.Any(x => x.ProductID == C.ProductID && x.UserID == user_id);
                    if (!IsThere)
                    {
                        C.UserID = User.Identity.GetUserId();
                        DB.Cart_Master.Add(C);
                        var Products = DB.Product_Master.Where(x => x.ProductID == C.ProductID).SingleOrDefault();
                        if (Products != null)
                        {
                            Products.ProductQuantity--;
                        }
                        DB.SaveChanges();
                        return(Ok("success"));
                    }
                    else
                    {
                        return(Ok("already"));
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult AddProduct(Products P)
        {
            var DB = new AngularDemoEntities();

            try
            {
                if (P != null)
                {
                    byte[] ImageFile = null;
                    if (!string.IsNullOrEmpty(P.ProductImage))
                    {
                        ImageFile = Convert.FromBase64String(P.ProductImage.Split(',')[1]);
                    }
                    Product_Master Obj_P = new Product_Master
                    {
                        CategoryID         = P.CategoryID,
                        InStock            = P.InStock,
                        ProductImage       = ImageFile,
                        ProductName        = P.ProductName,
                        ProductPrice       = P.ProductPrice,
                        ProductQuantity    = P.ProductQuantity,
                        ProductDescription = P.ProductDescription
                    };
                    DB.Product_Master.Add(Obj_P);
                    DB.SaveChanges();
                    return(Ok("success"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult RemoveCartItem(int ID)
        {
            var user_id = User.Identity.GetUserId();
            var DB      = new AngularDemoEntities();

            try
            {
                var Cart_item = DB.Cart_Master.Where(x => x.CartID == ID).FirstOrDefault();
                if (Cart_item != null)
                {
                    DB.Cart_Master.Remove(Cart_item);
                    DB.SaveChanges();
                    return(Ok("success"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
        public IHttpActionResult GetAllCount()
        {
            var DB      = new AngularDemoEntities();
            var user_id = User.Identity.GetUserId();

            try
            {
                int TotalUsers    = DB.AspNetUsers.Count();
                int TotalOrders   = DB.Order_Master.Count();
                int TotalProducts = DB.Product_Master.Count();

                IDictionary <string, int> C = new Dictionary <string, int>()
                {
                    { "TotalRegisteredUser", TotalUsers },
                    { "TotalOrders", TotalOrders },
                    { "TotalProducts", TotalProducts }
                };
                return(Ok(C));
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
 public IHttpActionResult ProductList()
 {
     try
     {
         var DB     = new AngularDemoEntities();
         var P_List = DB.Product_Master.Select(x => new
         {
             x.ProductID,
             x.CategoryID,
             x.Category_Master.CategoryName,
             x.ProductImage,
             x.ProductPrice,
             x.InStock,
             x.ProductQuantity,
             x.ProductName,
             x.ProductDescription
         }).OrderByDescending(y => y.ProductID).ToList();
         return(Ok(P_List));
     }
     catch (Exception ex)
     {
         throw ex.InnerException;
     }
 }