Exemplo n.º 1
0
        public async Task <int> SearchUserAsync()
        {
            var reader = new StreamReader(Request.Body);
            var body   = await reader.ReadToEndAsync();

            MongodbModel model          = new MongodbModel();
            Account      account        = JsonConvert.DeserializeObject <Account>(body);
            var          hashedPassword = Crypto.HashPassword(account.password);
            var          document       = new BsonDocument
            {
                { "email", account.email },
                { "password", hashedPassword }
            };

            if (await model.insertUserAsync(document) == 1)
            {
                return(1);
            }
            if (await model.insertUserAsync(document) == 0)
            {
                return(0);
            }
            else
            {
                return(2);
            }
        }
Exemplo n.º 2
0
        public async Task <string> ShowProductsAsync()
        {
            MongodbModel model    = new MongodbModel();
            var          products = await model.getAllProducts();

            Console.WriteLine(products);
            return(JsonConvert.SerializeObject(products));
        }
Exemplo n.º 3
0
        public async Task <string> searchAsync()
        {
            var          query    = Request.Query["q"];
            MongodbModel model    = new MongodbModel();
            var          products = await model.findProduct(query);

            Console.WriteLine(products);
            return(JsonConvert.SerializeObject(products));
        }
Exemplo n.º 4
0
        public async Task <string> FetchProduct()
        {
            var reader = new StreamReader(Request.Body);
            var body   = await reader.ReadToEndAsync();

            MongodbModel model   = new MongodbModel();
            Edit         account = JsonConvert.DeserializeObject <Edit>(body);

            return(await model.findProductByMatriculeAsync(account.matricule));
        }
Exemplo n.º 5
0
        public async Task <int> ajoutProduitAsync()
        {
            var reader = new StreamReader(Request.Body);
            var body   = await reader.ReadToEndAsync();

            System.Diagnostics.Debug.Write(body);
            MongodbModel model = new MongodbModel();

            return(await model.ajoutProduit(body));
        }
Exemplo n.º 6
0
        public async Task <string> DeleteProduct()
        {
            var reader = new StreamReader(Request.Body);
            var body   = await reader.ReadToEndAsync();

            MongodbModel model   = new MongodbModel();
            Product      product = JsonConvert.DeserializeObject <Product>(body);

            return(await model.deleteProduct(product.matricule));
        }
Exemplo n.º 7
0
        public async Task <string> editProduct()
        {
            var reader = new StreamReader(Request.Body);
            var body   = await reader.ReadToEndAsync();

            MongodbModel model   = new MongodbModel();
            Account      account = JsonConvert.DeserializeObject <Account>(body);

            return(await model.editAccount(account));
        }
Exemplo n.º 8
0
        public async Task <bool> GetStringAsync()
        {
            var reader = new StreamReader(Request.Body);
            var body   = await reader.ReadToEndAsync();

            MongodbModel model   = new MongodbModel();
            Account      account = JsonConvert.DeserializeObject <Account>(body);


            bool check = await model.loginCheck(account.email, account.password);

            if (check)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 9
0
        public async Task <string> editProduct()
        {
            var reader = new StreamReader(Request.Body);
            var body   = await reader.ReadToEndAsync();

            MongodbModel model   = new MongodbModel();
            Product      product = JsonConvert.DeserializeObject <Product>(body);

            model.editProduct(product);
            return(body);
            // Product product = JsonConvert.DeserializeObject<Product>(body);
            // var document = new BsonDocument
            // {
            //     { "email", product.email },
            //     { "prix", product.prix  },
            //     {"quantite",product.quantite},
            //     {"image",product.image},
            //     {"matricule",product.matricule},
            //     {"_id", new BsonObjectId(ObjectId.Parse(product.Id))}
            // };
            // Console.WriteLine(document);
            // return await model.editProduct(product, document);
        }
Exemplo n.º 10
0
        public async Task <int> GetCountGet()
        {
            MongodbModel model = new MongodbModel();

            return(await model.countDocs());
        }