Example #1
0
        public IActionResult DeleteImage(string token, [FromBody] List <ImageURL> imageURLs)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);

            if (RoleId)
            {
                if (ModelState.IsValid)
                {
                    foreach (var item in imageURLs)
                    {
                        ImageURL imageURL = new ImageURL();
                        imageURL.Id = item.Id;
                        _context.Remove(imageURL);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    var errors = ModelState.Select(x => x.Value.Errors)
                                 .Where(y => y.Count > 0)
                                 .ToList();
                    return(BadRequest(errors));
                }

                return(Ok("Images Deleted"));
            }

            return(Unauthorized());
        }
Example #2
0
        public IActionResult DeleteProduct(string token, [FromBody] List <Product> products)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);

            if (RoleId)
            {
                if (ModelState.IsValid)
                {
                    foreach (var item in products)
                    {
                        Product product = new Product();
                        product.Id = item.Id;
                        _context.Remove(product);
                    }
                    _context.SaveChanges();
                }
                else
                {
                    var errors = ModelState.Select(x => x.Value.Errors)
                                 .Where(y => y.Count > 0)
                                 .ToList();
                    return(BadRequest(errors));
                }

                return(Ok("Product(s) Deleted"));
            }

            return(Unauthorized());
        }
Example #3
0
 public IQueryable Get(int id, string token)
 {
     if (token == null)
     {
         var result = from p in this._context.products
                      join i in this._context.imageURLs
                      on p.Id equals i.ProductId into imageURLsGroup
                      where p.Id == id
                      select new
         {
             Product     = p,
             Image       = imageURLsGroup.ToList(),
             isFavourite = false
         };
         return(result);
     }
     else
     {
         int userid = JWTValidator.IDTokenValidation(token);
         var result = from p in this._context.products
                      join i in this._context.imageURLs
                      on p.Id equals i.ProductId into imageURLsGroup
                      where p.Id == id
                      let isFavourite = (from f in this._context.favourites where f.ProductId == id && f.UserId == userid select f).Any()
                                        select new
         {
             Product     = p,
             Image       = imageURLsGroup.ToList(),
             isFavourite = isFavourite
         };
         return(result);
     }
 }
        public IActionResult GetUser(string token)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);

            if (RoleId)
            {
                var result = (from m in _context.users select m).Count();

                return(Ok(result));
            }
            return(Unauthorized());
        }
        public IActionResult GetProductsStatistics(string token)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);

            if (RoleId)
            {
                var result = (from m in _context.products orderby m.Stock ascending select m).Take(10);

                return(Ok(result));
            }
            return(Unauthorized());
        }
Example #6
0
        public void DeleteSingle(int productId, string token)
        {
            int id     = JWTValidator.IDTokenValidation(token);
            var remove = (from a_b in _context.ShoppingCarts
                          where a_b.UserId == id && a_b.ProductId == productId
                          select a_b).FirstOrDefault();

            if (remove != null)
            {
                _context.ShoppingCarts.Remove(remove);
                _context.SaveChanges();
            }
        }
        public IQueryable <User> GetAccount(string token)
        {
            if (token == null)
            {
                token = "eyJFTUFJTCI6IiIsIklEIjoiMCIsIlJPTEUgSUQiOiIxIn0=";
            }

            int id = JWTValidator.IDTokenValidation(token);

            //get a specific user
            var result = from m in this._context.users where m.Id == id select m;

            return(result);
        }
Example #8
0
        public IActionResult GetImages(string token, [FromQuery] ImageURL i)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);

            if (RoleId)
            {
                var query = _context.imageURLs.OrderBy(m => i.Id);
                return(Ok(query));
            }
            else
            {
                return(Unauthorized());
            }
        }
        public IActionResult Getpending(string token)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);

            if (RoleId)
            {
                var result = (from m in _context.History where m.Status == "Pending" select m).Count();



                return(Ok(result));
            }
            return(Unauthorized());
        }
Example #10
0
        public Boolean Get(string token, int ProductId)
        {
            if (token == null)
            {
                token = "eyJFTUFJTCI6IiIsIklEIjoiMCIsIlJPTEUgSUQiOiIxIn0=";
            }

            int id1    = JWTValidator.IDTokenValidation(token);
            var result = (from a_b in _context.ShoppingCarts
                          where a_b.UserId == id1 && a_b.ProductId == ProductId
                          select a_b).Any();

            return(result);
        }
Example #11
0
        public IActionResult GetUsers(string token, [FromQuery] User u)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);
            int  UserId = JWTValidator.IDTokenValidation(token);

            if (RoleId)
            {
                var query = _context.users.Where(f => f.Id != UserId).OrderBy(m => u.Id);
                return(Ok(query));
            }
            else
            {
                return(Unauthorized());
            }
        }
Example #12
0
        public IActionResult ProductEdit(string token, int productid, [FromBody] Product p)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);
            var  edit   = _context.products.Find(productid);

            if (RoleId)
            {
                if (p.Name != null)
                {
                    edit.Name = p.Name;
                }
                if (p.Description != null)
                {
                    edit.Description = p.Description;
                }
                if (p.Price != default(float))
                {
                    edit.Price = p.Price;
                }
                if (p.FirstImg != null)
                {
                    edit.FirstImg = p.FirstImg;
                }
                if (p.Stock != default(int))
                {
                    edit.Stock = p.Stock;
                }

                if (ModelState.IsValid)
                {
                    _context.products.Update(edit);
                    _context.SaveChanges();
                }
                else
                {
                    var errors = ModelState.Select(x => x.Value.Errors)
                                 .Where(y => y.Count > 0)
                                 .ToList();
                    return(BadRequest(errors));
                }

                return(Ok("Product updated"));
            }

            return(Unauthorized());
        }
        public void UpdateStock(string token)
        {
            int id     = JWTValidator.IDTokenValidation(token);
            var result = from p in this._context.products
                         from s in this._context.ShoppingCarts
                         where p.Id == s.ProductId && s.UserId == id
                         select new { p, s };

            foreach (var item in result)
            {
                item.p.Stock = item.p.Stock - item.s.Amount;
                if (item.p.Stock < 0)
                {
                    item.p.Stock = 0;
                }
            }
        }
Example #14
0
        public IQueryable Get(string token)
        {
            if (token == null)
            {
                token = "eyJFTUFJTCI6IiIsIklEIjoiMCIsIlJPTEUgSUQiOiIxIn0=";
            }

            int id = JWTValidator.IDTokenValidation(token);

            var result = from u in _context.users
                         from p in _context.products
                         from u_p in _context.favourites
                         where u.Id == id && u_p.UserId == id && u_p.ProductId == p.Id
                         select p;

            return(result);
        }
        public IQueryable Get(string token)
        {
            int id = JWTValidator.IDTokenValidation(token);

            var result = from h in this._context.History
                         where h.UserId == id
                         select new
            {
                productName  = h.Product.Name,
                amount       = h.Amount,
                totalPrice   = (double)h.Product.Price * (double)h.Amount,
                image        = h.Product.FirstImg,
                purchaseDate = h.Date,
                status       = h.Status
            };

            return(result);
        }
        public IActionResult UpdateHistory(string token)
        {
            string Total  = "";
            int    id     = JWTValidator.IDTokenValidation(token);
            var    result = from s in this._context.ShoppingCarts
                            where s.UserId == id
                            select s;

            foreach (var item in result)
            {
                History history = new History();
                history.Amount    = item.Amount;
                history.Date      = DateTime.Now.ToString();
                history.ProductId = item.ProductId;
                history.UserId    = item.UserId;
                history.Status    = "Pending";
                _context.Add(history);
                string GetProduct()
                {
                    var Productname = (from p in this._context.products
                                       where history.ProductId == p.Id
                                       select p.Name).First();

                    return(Productname);
                }

                Total = Total + "<li>" + GetProduct() + " " + history.Amount.ToString() + "x" + "</li>";
            }
            string GetMail()
            {
                var mailinfo = (from u in this._context.users
                                where u.Id == id
                                select u.email).First();

                return(mailinfo);
            }

            UpdateStock(token);
            Mail.MailProduct.PurchaseMail(GetMail(), Total);
            DeleteAll(id);
            _context.SaveChanges();
            return(Ok("Geschiedenis bijgewerkt"));
        }
Example #17
0
        public void Delete(string token, int productId)
        {
            if (token == null)
            {
                token = "eyJFTUFJTCI6IiIsIklEIjoiMCIsIlJPTEUgSUQiOiIxIn0=";
            }

            int id = JWTValidator.IDTokenValidation(token);

            var remove = (from a_b in _context.favourites
                          where a_b.UserId == id && a_b.ProductId == productId
                          select a_b).FirstOrDefault();

            if (remove != null)
            {
                _context.favourites.Remove(remove);
                _context.SaveChanges();
            }
        }
Example #18
0
        public IActionResult ProductAdd(string token, [FromBody] Product p, string name, string Description, float price, string FirstIMG, int stock, int category, int subcategory)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);

            if (RoleId)
            {
                var a           = this._context.products.OrderByDescending(pr => pr.Id).FirstOrDefault();
                var ProductData = from product in _context.products
                                  where (name == p.Name &&
                                         Description == p.Description &&
                                         price == p.Price &&
                                         FirstIMG == p.FirstImg &&
                                         stock == p.Stock &&
                                         category == p.CategoryId &&
                                         subcategory == p.SubCategoryId)
                                  select p;
                p.Id = a.Id + 1;

                if (p.Name == null || p.Description == null || p.Price == default(float) || p.Price <= 0 || p.FirstImg == null || p.CategoryId <= 0 || p.SubCategoryId <= 0)
                {
                    return(BadRequest("A.U.B vul alle velden in met geldige waarde (CategoryId, SubCategory en Price moeten groter zijn dan 0)"));
                }

                if (ModelState.IsValid)
                {
                    _context.products.Add(p);
                    _context.SaveChanges();
                }
                else
                {
                    var errors = ModelState.Select(x => x.Value.Errors)
                                 .Where(y => y.Count > 0)
                                 .ToList();
                    return(BadRequest(errors));
                }

                return(Ok("Product added"));
            }
            else
            {
                return(Unauthorized());
            }
        }
Example #19
0
        public void DeleteAll(string token)
        {
            int id     = JWTValidator.IDTokenValidation(token);
            var remove = (from a_b in _context.ShoppingCarts
                          where a_b.UserId == id
                          select a_b).ToList();

            foreach (var item in remove)
            {
                if (item != null)
                {
                    _context.ShoppingCarts.Remove(item);
                    _context.SaveChanges();
                }
                else
                {
                    Unauthorized();
                }
            }
        }
Example #20
0
        public IActionResult GetProducts(string token, [FromQuery] Product p)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);

            if (RoleId)
            {
                var query = from pr in _context.products
                            join i in this._context.imageURLs
                            on pr.Id equals i.ProductId into imageURLsGroup
                            let NoI = imageURLsGroup.Count()
                                      select new {
                    Product        = pr,
                    NumberOfImages = NoI
                };
                return(Ok(query));
            }
            else
            {
                return(Unauthorized());
            }
        }
        public IQueryable Get3(int categoryId, int subCategoryId, string token)
        {
            if (token == null)
            {
                var result = from c in this._context.categories
                             from s in this._context.SubCategories
                             join p in this._context.products
                             on s.Id equals p.SubCategory.Id
                             where c.Id == categoryId && s.Id == subCategoryId
                             select p;

                return(result);
            }
            else
            {
                int id = JWTValidator.IDTokenValidation(token);

                var result = from c in this._context.categories
                             from s in this._context.SubCategories
                             join p in this._context.products
                             on s.Id equals p.SubCategory.Id
                             let isFavourite = (
                    from f in _context.favourites
                    where p.Id == f.ProductId && f.UserId == id
                    select p).Any()
                                               where c.Id == categoryId && s.Id == subCategoryId
                                               orderby p.Id
                                               select new
                {
                    isFavourite = isFavourite,
                    Id          = p.Id,
                    Name        = p.Name,
                    Description = p.Description,
                    Price       = p.Price,
                    FirstImg    = p.FirstImg
                };

                return(result);
            }
        }
Example #22
0
        public IActionResult Post([FromBody] Favourite f, string token)
        {
            if (f == null)
            {
                return(NoContent());
            }
            else
            {
                if (token == null)
                {
                    token = "eyJFTUFJTCI6IiIsIklEIjoiMCIsIlJPTEUgSUQiOiIxIn0=";
                }

                int id = JWTValidator.IDTokenValidation(token);

                f.UserId = id;
                _context.Add(f);
                _context.SaveChanges();

                return(Ok());
            }
        }
Example #23
0
        public IActionResult Post([FromBody] ShoppingCart s, string token)
        {
            int id = JWTValidator.IDTokenValidation(token);

            var ProdDate = (from s2 in _context.ShoppingCarts
                            where (id == s2.UserId &&
                                   s.ProductId == s2.ProductId)
                            select s2);

            if (s.UserId != id)
            {
                Unauthorized();
            }

            //checking for dupe users
            bool DupeUser = _context.ShoppingCarts.Any(dupe => dupe.UserId == id);
            bool DupeProd = _context.ShoppingCarts.Any(dupe => dupe.ProductId == s.ProductId);



            if (DupeUser && DupeProd)
            {
                var UserData = (from s1 in _context.ShoppingCarts where s1.UserId == id && s1.ProductId == s.ProductId select s1.Amount).ToList();

                s.Amount = s.Amount + UserData[0];
                s.UserId = id;
                _context.Update(s);
                _context.SaveChanges();
            }
            else
            {
                s.UserId = id;
                _context.Add(s);
                _context.SaveChanges();
            }


            return(Ok());
        }
Example #24
0
        public IQueryable Random(string token)
        {
            if (token == null)
            {
                var result = (from p in _context.products
                              select new
                {
                    Id = p.Id,
                    Description = p.Description,
                    Price = p.Price,
                    FirstImg = p.FirstImg,
                    Name = p.Name,
                    stock = p.Stock
                }).OrderBy(x => Guid.NewGuid()).Take(20);             // 20 is het hoeveel random items je wilt, verander how you see fit :3 o/ Sorry dat het zo lang duurde :'(


                return(result.Distinct());
            }
            else
            {
                int id     = JWTValidator.IDTokenValidation(token);
                var result = (from p in _context.products
                              let isFavourite = (from f in _context.favourites where p.Id == f.ProductId && f.UserId == id select p).Any()
                                                select new
                {
                    Id = p.Id,
                    Description = p.Description,
                    Price = p.Price,
                    FirstImg = p.FirstImg,
                    Name = p.Name,
                    stock = p.Stock,
                    isFavourite = isFavourite,
                }).OrderBy(x => Guid.NewGuid()).Take(20);             // 20 is het hoeveel random items je wilt, verander how you see fit :3 o/ Sorry dat het zo lang duurde :'(


                return(result.Distinct());
            }
        }
Example #25
0
        public IQueryable Get(string token)
        {
            if (token == null)
            {
                var result = from p in _context.products
                             orderby p.Id
                             select new
                {
                    isFavourite = false,
                    Id          = p.Id,
                    Name        = p.Name,
                    Description = p.Description,
                    Price       = p.Price,
                    FirstImg    = p.FirstImg
                };

                return(result);
            }
            else
            {
                int id = JWTValidator.IDTokenValidation(token);

                var result = from p in _context.products
                             let isFavourite = (from f in _context.favourites where p.Id == f.ProductId && f.UserId == id select p).Any()
                                               orderby p.Id
                                               select new
                {
                    isFavourite = isFavourite,
                    Id          = p.Id,
                    Name        = p.Name,
                    Description = p.Description,
                    Price       = p.Price,
                    FirstImg    = p.FirstImg
                };

                return(result);
            }
        }
Example #26
0
        public IQueryable Search(string searchquery, string token)
        {
            if (token == null)
            {
                var result = from p in this._context.products
                             from c in this._context.categories
                             where (p.Description.ToString().ToLower().Contains(searchquery.ToLower()) ||
                                    p.Name.ToString().ToLower().Contains(searchquery.ToLower()) ||
                                    (c.Name.ToString().ToLower().Contains(searchquery.ToLower()) && p.Category.Id == c.Id))
                             orderby p.Id
                             select p;
                return(result.Distinct());
            }
            else
            {
                int id = JWTValidator.IDTokenValidation(token);

                var result = from p in this._context.products
                             from c in this._context.categories
                             let isFavourite = (from f in _context.favourites where p.Id == f.ProductId && f.UserId == id select p).Any()
                                               where (p.Description.ToString().ToLower().Contains(searchquery.ToLower()) ||
                                                      p.Name.ToString().ToLower().Contains(searchquery.ToLower()) ||
                                                      (c.Name.ToString().ToLower().Contains(searchquery.ToLower()) && p.Category.Id == c.Id))
                                               orderby p.Id
                                               select new
                {
                    isFavourite = isFavourite,
                    Id          = p.Id,
                    Name        = p.Name,
                    Description = p.Description,
                    Price       = p.Price,
                    FirstImg    = p.FirstImg
                };
                return(result.Distinct());
            }
        }
Example #27
0
        public IActionResult CreateUser(string token, [FromBody] User u, string name, string lastname, string birthday, string password, string gender, string streetname, string email, string housenumber, string addition, string postalcode, string city, string phonenumber)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);

            if (RoleId)
            {
                var UserData = from user in _context.users
                               where (name == u.Name &&
                                      lastname == u.LastName &&
                                      birthday == u.Birthday &&
                                      password == u.Password &&
                                      gender == u.Gender &&
                                      streetname == u.Street_Name &&
                                      email == u.email &&
                                      housenumber == u.House_Number &&
                                      addition == u.Addition &&
                                      postalcode == u.Postalcode &&
                                      city == u.City &&
                                      phonenumber == u.Telephone_Number)
                               select u;

                if (u.Name == null || u.LastName == null || u.Birthday == null || u.Password == null || u.Gender == null || u.Street_Name == null || u.email == null || u.House_Number == null || u.Addition == null || u.Postalcode == null || u.City == null || u.Telephone_Number == null)
                {
                    return(BadRequest("A.U.B Alle velden invullen"));
                }

                //Check for potential errors
                bool DupeMail   = _context.users.Any(Dupe => Dupe.email == u.email);
                bool PhoneCheck = _context.users.Any(CheckPhone => CheckPhone.Telephone_Number == u.Telephone_Number);


                //Criteria check
                if (DupeMail)
                {
                    return(BadRequest("Email bestaat niet of is al in gebruik"));
                }
                if (PhoneCheck)
                {
                    return(BadRequest("Telefoon nummer bestaat niet of is al in gebruik"));
                }
                if (DupeMail == false && PhoneCheck == false)
                {
                    if (ModelState.IsValid)
                    {
                        _context.users.Add(u);
                        _context.SaveChanges();
                        return(Ok("Account Created"));
                    }
                    else
                    {
                        var errors = ModelState.Select(x => x.Value.Errors)
                                     .Where(y => y.Count > 0)
                                     .ToList();
                        return(BadRequest(errors));
                    }
                }

                return(Ok("Account Created."));
            }
            else
            {
                return(Unauthorized());
            }
        }
Example #28
0
        public Boolean CheckAdminStatus(string token)
        {
            bool Validation = JWTValidator.RoleIDTokenValidation(token);

            return(Validation);
        }
        public IActionResult Update(string token, [FromBody] User user)
        {
            if (token == null)
            {
                token = "eyJFTUFJTCI6IiIsIklEIjoiMCIsIlJPTEUgSUQiOiIxIn0=";
            }

            int id   = JWTValidator.IDTokenValidation(token);
            var edit = _context.users.Find(id);

            if (user.Password != null)
            {
                edit.Password = user.Password;
            }
            if (user.Street_Name != null)
            {
                edit.Street_Name = user.Street_Name;
            }
            if (user.email != null)
            {
                edit.email = user.email;
            }
            if (user.House_Number != null)
            {
                edit.House_Number = user.House_Number;
            }
            if (user.Addition != null)
            {
                edit.Addition = user.Addition;
            }
            if (user.Postalcode != null)
            {
                edit.Postalcode = user.Postalcode;
            }
            if (user.City != null)
            {
                edit.City = user.City;
            }
            if (user.Telephone_Number != null)
            {
                edit.Telephone_Number = user.Telephone_Number;
            }

            //Check for potential errors
            bool DupeMail   = _context.users.Any(Dupe => Dupe.email == user.email);
            bool PhoneCheck = _context.users.Any(CheckPhone => CheckPhone.Telephone_Number == user.Telephone_Number);


            //Criteria check
            if (DupeMail)
            {
                return(BadRequest("Email bestaat niet of is al in gebruik"));
            }
            if (PhoneCheck)
            {
                return(BadRequest("Telefoon nummer bestaat niet of is al in gebruik"));
            }
            if (DupeMail == false && PhoneCheck == false)
            {
                if (ModelState.IsValid)
                {
                    _context.users.Update(edit);
                    _context.SaveChanges();
                }
                else
                {
                    var errors = ModelState.Select(x => x.Value.Errors)
                                 .Where(y => y.Count > 0)
                                 .ToList();
                    return(BadRequest(errors));
                }
            }

            return(Ok("Account edited"));
        }
Example #30
0
        public IActionResult Update(string token, int userid, [FromBody] User user)
        {
            bool RoleId = JWTValidator.RoleIDTokenValidation(token);
            var  edit   = _context.users.Find(userid);

            if (RoleId)
            {
                if (user.Name != null)
                {
                    edit.Name = user.Name;
                }
                if (user.LastName != null)
                {
                    edit.LastName = user.LastName;
                }
                if (user.Birthday != null)
                {
                    edit.Birthday = user.Birthday;
                }
                if (user.Gender != null)
                {
                    edit.Gender = user.Gender;
                }
                if (user.Password != null)
                {
                    edit.Password = user.Password;
                }
                if (user.Street_Name != null)
                {
                    edit.Street_Name = user.Street_Name;
                }
                if (user.email != null)
                {
                    edit.email = user.email;
                }
                if (user.House_Number != null)
                {
                    edit.House_Number = user.House_Number;
                }
                if (user.Addition != null)
                {
                    edit.Addition = user.Addition;
                }
                if (user.Postalcode != null)
                {
                    edit.Postalcode = user.Postalcode;
                }
                if (user.City != null)
                {
                    edit.City = user.City;
                }

                if (user.Telephone_Number != null)
                {
                    edit.Telephone_Number = user.Telephone_Number;
                }

                //Check for potential errors
                bool DupeMail   = _context.users.Any(Dupe => Dupe.email == user.email);
                bool PhoneCheck = _context.users.Any(CheckPhone => CheckPhone.Telephone_Number == user.Telephone_Number);


                //Criteria check
                if (DupeMail)
                {
                    return(BadRequest("Email bestaat niet of is al in gebruik"));
                }
                if (PhoneCheck)
                {
                    return(BadRequest("Telefoon nummer bestaat niet of is al in gebruik"));
                }
                if (DupeMail == false && PhoneCheck == false)
                {
                    if (ModelState.IsValid)
                    {
                        _context.users.Update(edit);
                        _context.SaveChanges();
                    }
                    else
                    {
                        var errors = ModelState.Select(x => x.Value.Errors)
                                     .Where(y => y.Count > 0)
                                     .ToList();
                        return(BadRequest(errors));
                    }
                }

                return(Ok("Account edited"));
            }
            else
            {
                return(Unauthorized());
            }
        }