Example #1
0
        public List <ITableModel> GetAll()
        {
            using (var response = APIClientConfig.ApiClient.GetAsync("tables"))
            {
                response.Wait();

                if (response.Result.IsSuccessStatusCode)
                {
                    var readTask = response.Result.Content.ReadAsAsync <List <TableModel> >();
                    readTask.Wait();

                    List <ITableModel> model = readTask.Result.ToList <ITableModel>();

                    ISoldProductDataAccess soldProductData = Factory.InstanceSoldProductDataAccess();

                    foreach (ITableModel table in model)
                    {
                        table.SoldProducts = soldProductData.GetByTable(table.ID);
                    }

                    return(model);
                }
                else
                {
                    throw new Exception(response.Result.ReasonPhrase);
                }
            }
        }
Example #2
0
        public ActionResult TableAddProduct(int?idTable, int?idCategory, int?idProduct)
        {
            if (idProduct != null)
            {
                try
                {
                    // Finding the selected product and the table where is going to be added
                    ITableModel   table   = tableData.FindById((int)idTable);
                    IProductModel product = productData.FindById((int)idProduct);

                    if (product == null)
                    {
                        log.Error("Could't find a product in the Database - return null");
                        return(View("ErrorAddProduct"));
                    }

                    // Creates a SoldProductModel from a ProductModel that can be added to a list in each TableModel
                    ISoldProductModel soldProduct = MappingObjects.ProductToSoldProduct(product, (int)idTable, tableData);
                    soldProductData.Create(soldProduct);

                    // Sets the current table as opened (Occupied by products)
                    table.Occupied = true;
                    tableData.Update(table);
                    table.SoldProducts = soldProductData.GetByTable(table.ID);

                    // Joins list of products and selected table to a single model
                    mainPageModel.Products = productData.GetBySubGroup((int)idCategory).OrderBy(x => x.Name).ToList();;
                    mainPageModel.Tables.Add(table);
                }
                catch (Exception ex)
                {
                    log.Error("Could't load products, sold products or tables from Database", ex);
                    return(View("ErrorRetriveData"));
                }

                return(View(mainPageModel));
            }
            else
            {
                log.Error("The product ID was null while trying to access");
                return(View("ErrorAddProduct"));
            }
        }
Example #3
0
        public ITableModel FindById(int id)
        {
            using (var response = APIClientConfig.ApiClient.GetAsync($"tables/{id}"))
            {
                response.Wait();

                if (response.Result.IsSuccessStatusCode)
                {
                    var readTask = response.Result.Content.ReadAsAsync <TableModel>();
                    readTask.Wait();

                    ITableModel            model           = readTask.Result;
                    ISoldProductDataAccess soldProductData = Factory.InstanceSoldProductDataAccess();

                    model.SoldProducts = soldProductData.GetByTable(id);

                    return(model);
                }
                else
                {
                    throw new Exception(response.Result.ReasonPhrase);
                }
            }
        }