public async void RemoveProduct([FromHeader] string auth, [FromForm] string uid, [FromForm] string prod)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            HttpContext.Response.Headers.Add("auth", auth);
            if (!ProductStore.Exists(prod).Result || !InventoryStore.Exists(uid, user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            await InventoryStore.RemoveProd(uid, prod, user);
        }
Exemple #2
0
        public async void EditProduct([FromHeader] string auth, [FromForm] string product,
                                      [FromForm] string uid, [FromForm] long quantity)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            HttpContext.Response.Headers.Add("auth", auth);
            if (!ProductStore.Exists(product).Result || !ShoppingListStore.Exists(uid, user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            await ShoppingListStore.Restock(uid, product, quantity, user);
        }
        public async void EditProduct([FromHeader] string auth, [FromForm] string product,
                                      [FromForm] string uid, [FromForm] DateTime?expire = null, [FromForm] long?quantity = null)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            HttpContext.Response.Headers.Add("auth", auth);
            if (!ProductStore.Exists(product).Result || !InventoryStore.Exists(uid, user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            var date = expire != null ? new LocalDateTime((DateTime)expire) : null;
            await InventoryStore.Restock(uid, product, user, quantity, date);
        }