//Reads a single order and returns Order
        private Order ReadTable(DataTable dataTable)
        {
            foreach (DataRow dr in dataTable.Rows)
            {
                RestaurantTable table = new RestaurantTable(
                    (int)dr["table_number"],
                    (bool)dr["is_occupied"],
                    (int)dr["number_of_seats"]
                    );

                Employee employee = new Employee(
                    (int)dr["employee_id"],
                    dr["name"].ToString(),
                    (int)dr["role"],
                    (int)dr["password"]
                    );

                Order order = new Order(
                    (int)dr["order_id"],
                    table,
                    employee,
                    Get_OrderItem_By_OrderID((int)(dr["order_id"])),
                    (bool)dr["is_payed"],
                    (decimal)dr["tip"],
                    (decimal)dr["total_cost"],
                    (string)dr["feedback"]);

                return(order);
            }

            return(null);
        }
Exemplo n.º 2
0
        public bool AddReservation(Reservation reservation, string userId, int restaurantId, int reservationTableSeats)
        {
            Visitor    visitor    = this.GetVisitorByUserId(userId);
            Restaurant restaurant = this.GetRestaurantByRestaurantId(restaurantId);

            reservation.Visitor    = visitor;
            reservation.Restaurant = restaurant;
            RestaurantTable restaurantTable = _dbContext.RestaurantTables
                                              .Include(r => r.Reservations)
                                              .Where(r => r.RestaurantTableSeats == reservationTableSeats && r.Restaurant.Id == restaurantId)
                                              .FirstOrDefault(r => r.CanAddReservation(reservation));

            if (restaurantTable == null)
            {
                return(false);
            }

            reservation.RestaurantTable = restaurantTable;
            reservation.Visitor         = visitor;
            visitor.VisitorReservations.Add(reservation);
            restaurantTable.Reservations.Add(reservation);
            _dbContext.SaveChanges();

            return(true);
        }
Exemplo n.º 3
0
        // GET: Hotel
        public PartialViewResult Register()
        {
            RestaurantTable hotel = new RestaurantTable();

            hotel.Address = "Bangalore"; //Initialization could be done to the Model and inject it to the Http Get....
            return(PartialView(hotel));  //Similar to Usercontrols of ASPX pages...
        }
        public void Db_Add_Order(RestaurantTable table, Employee employee, List <OrderItem> orderItemList)
        {
            // Get id of the order based on the table number
            int orderMainId = Db_Get_Table_OrderId(table.TableId);

            // If the orderMainId is 0, then there is not an order for that table in the database
            if (orderMainId == 0)
            {
                // Add a new order to the database and return the auto_incremented primary key value of it
                orderMainId = Db_Add_New_Order(table, employee);
            }

            /*
             * When we add the order items to the database we also need to deduct it from the stock.
             *
             * We use a SqlTransaction for it, to be able to sent the items to thet database in bulk,
             * and cancel the transaction when an error occurs.
             */
            SqlConnection  conn        = OpenConnection();
            SqlTransaction transaction = conn.BeginTransaction();

            Db_Add_Order_Items(orderMainId, orderItemList, transaction);
            Db_Deduct_Item_Stock(orderItemList, transaction);

            // Commit all the items to the database
            transaction.Commit();

            // Close connection
            conn.Close();
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddTable(AddTableViewModel tableViewModel)
        {
            var user = await _userManager.FindByIdAsync(HttpContext.User.GetUserId());

            //ApplicationUser applicationUser = await _context.ApplicationUsers.FirstOrDefaultAsync(w => w.Id == user.Id);
            //Restaurant restaurantData = await _context.Restaurants.FirstOrDefaultAsync(w => w.ApplicationUser.Id == user.Id);
            if (user.AccountType == "Restaurant")
            {
                Restaurant restaurant = _applicationService.GetRestaurantByUserId(user.Id);
                if (ModelState.IsValid)
                {
                    RestaurantTable table = new RestaurantTable()
                    {
                        RestaurantTableSeats = tableViewModel.TableSeats
                    };
                    //_context.RestaurantTables.Add(table);
                    _applicationService.AddTableByRestaurantId(table, restaurant.Id);
                    if (restaurant == null)
                    {
                        user.RestaurantData = new Restaurant();
                    }
                    if (restaurant.RestaurantTables == null)
                    {
                        user.RestaurantData.RestaurantTables = new List <RestaurantTable>();
                    }
                    restaurant.RestaurantTables.Add(table);
                    //_context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            return(View(tableViewModel));
        }
 public HttpResponseMessage UpdateTable(int id, [FromBody] RestaurantTable tables)
 {
     using (GlobalDesignEntities entities = new GlobalDesignEntities())
     {
         try
         {
             var entity = entities.RestaurantTable.FirstOrDefault(e => e.Id == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Tables not found"));
             }
             else
             {
                 entity.TableName       = tables.TableName;
                 entity.TableSeatNumber = tables.TableSeatNumber;
                 entity.TableBooking    = tables.TableBooking;
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
         }
         catch (Exception ex)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }
Exemplo n.º 7
0
        MainForm _master;          //Receives an instance of the MainForm(parent) so that it can be easily updated after changes are made

        //Constructor which receives an instance of the MainForm and the RestaurantTable which the form is going to work with
        public EditTableForm(RestaurantTable item, MainForm _master)
        {
            table        = item;
            this._master = _master;
            InitializeComponent();

            this.FormBorderStyle = FormBorderStyle.None;
            availability         = item.Available;

            //Blocks the user from creating reservations for a RestaurantTable that does not exist
            if (item.objectId == null)
            {
                btnViewDetails.Enabled = false;
            }
            //Determines which text should appear on the button
            if (availability == true)
            {
                btnDisable.Text = "Make Table Unavailable";
            }
            else
            {
                btnDisable.Text = "Make Table Available";
            }

            //Populates some textboxes with the appropriate information
            edtName.Text     = item.Name;
            spnSeating.Value = item.Capacity;
            rtbInfo.Text     = item.TableInfo;
        }
        public async Task <RestaurantTable> Add(RestaurantTable model)
        {
            var entity = _restaurantTableRepository.Add(model);
            await _restaurantTableRepository.SaveChangeAsync();

            return(model);
        }
        private List <Order> ReadTables(DataTable dataTable)
        {
            List <Order> orders = new List <Order>();

            foreach (DataRow dr in dataTable.Rows)
            {
                RestaurantTable table = new RestaurantTable(
                    (int)dr["table_number"],
                    (bool)dr["is_reserved"],
                    (int)dr["number_of_seats"]
                    );

                Employee employee = new Employee(
                    (int)dr["employee_id"],
                    dr["name"].ToString(),
                    (int)dr["role"],
                    (int)dr["password"]
                    );

                Order order = new Order(
                    (int)dr["order_id"],
                    table,
                    employee,
                    Get_OrderItem_By_OrderID((int)(dr["order_id"])),
                    (bool)dr["is_payed"],
                    (decimal)dr["tip"],
                    (decimal)dr["total_cost"],
                    (string)dr["feedback"]
                    );

                orders.Add(order);
            }
            return(orders);
        }
Exemplo n.º 10
0
        public ActionResult Delete(int id, RestaurantTable resttab)
        {
            var deleteRest = db.RestaurantTables.Where(e => e.RestaurantId == id).FirstOrDefault();

            db.RestaurantTables.Remove(deleteRest);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
        public ActionResult Register(RestaurantTable model)
        {
            var dbContext = new inTimeDatabaseEntities();

            dbContext.RestaurantTables.Add(model);
            dbContext.SaveChanges();
            return(RedirectToAction("Home"));
        }
Exemplo n.º 12
0
        public ActionResult Add(RestaurantTableModel model, HttpPostedFileBase floorplan)
        {
            try
            {
                //Explicitly Validate Model for floorplan image or previous image guid
                var floorplanfileguid = Guid.Empty;
                if (floorplan == null && !Guid.TryParse(model.FloorPlanFileName, out floorplanfileguid))
                {
                    ModelState.AddModelError("addstatus", "One of the Given Floor Plans need to be selected");
                }
                if (floorplan != null && (floorplan.ContentLength < 1 || (floorplan.ContentType != "image/jpeg" && floorplan.ContentType != "image/png")))
                {
                    ModelState.AddModelError("addstatus", "A Floor Plan needs to have a valid Floor Plan Image, Only JPEG and PNG images are supported");
                }
                if (ModelState.IsValid)
                {
                    // Attempt to add the offer
                    var restauranttable = new RestaurantTable
                    {
                        TableType         = model.TableType,
                        Alignment         = model.Alignment,
                        Position          = new Point(model.PositionX, model.PositionY),
                        Price             = model.Price,
                        FloorPlanFileName = floorplanfileguid == Guid.Empty ? new ImagesController().PutImage(floorplan, null).ToString("n") : floorplanfileguid.ToString("n")
                    };

                    var tableid = Repository.Add(restauranttable);
                    if (tableid > 0)
                    {
                        TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                        {
                            Message = String.Format("Table Id:{0}, with seating capacity of {1} was successfully Added", tableid, (int)model.TableType),
                            Result  = true,
                            State   = ActionResultNotification.MessageState.Information
                        };
                        return(RedirectToAction("Index"));
                    }
                }
                // If we got this far, something failed, redisplay form
                TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                {
                    Message = ModelState.ContainsKey("addstatus") ? ModelState["addstatus"].Errors[0].ErrorMessage : "There was an Error in adding the new Table, please try again",
                    Result  = false,
                    State   = ActionResultNotification.MessageState.Error
                };
                return(View(model));
            }
            catch (Exception e)
            {
                TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                {
                    Message = e.Message,
                    Result  = false,
                    State   = ActionResultNotification.MessageState.Error
                };
                return(View(model));
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// edit a table
        /// </summary>
        /// <param name="restaurantTable">object of restaurant table</param>
        /// <returns>restaurant table object</returns>
        public RestaurantTable EditTable(RestaurantTable restaurantTable)
        {
            Database db        = Database.Open(DatabaseName);
            var      dbCommand = "UPDATE RestaurantTable SET (Available = @1, TableNumber = @2, NumberOfChairs = @3) WHERE Id = @0";

            db.QuerySingle(dbCommand, restaurantTable.Id, restaurantTable.Available, restaurantTable.TableNumber, restaurantTable.NumberOfChairs);
            db.Close();
            return(restaurantTable);
        }
Exemplo n.º 14
0
 public Sales(RestaurantTable selectedRestaurantTable) : this()
 {
     // FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;
     InitializeComponent();
     this.SelectedRestaurantTable = selectedRestaurantTable;
     Task.Run(() => Init()).Wait();
     DataContext = vm;
     IsDirty     = false;
 }
        public async Task <bool> Put(RestaurantTable model)
        {
            var result = false;

            if (ModelState.IsValid)
            {
                result = await _restaurantTableBusiness.Update(model);
            }
            return(result);
        }
Exemplo n.º 16
0
        public ActionResult Edit(RestaurantTable resttab)
        {
            var updatedrest = db.RestaurantTables.Where(e => e.RestaurantId == resttab.RestaurantId).FirstOrDefault();

            updatedrest.Name   = resttab.Name;
            updatedrest.Cusine = resttab.Cusine;

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 17
0
        /// <summary>
        /// get a table
        /// </summary>
        /// <param name="Id">id</param>
        /// <returns>table object</returns>
        public RestaurantTable GetTable(int Id)
        {
            Database db            = Database.Open(DatabaseName);
            string   insertCommand = "SELECT * FROM RestaurantTable WHERE Id = @0";
            var      row           = db.QuerySingle(insertCommand, Id);

            db.Close();
            var table = new RestaurantTable(row.Id, row.RestaurantId, row.Available, row.TableNumber, row.NumberOfChairs);

            return(table);
        }
Exemplo n.º 18
0
        //Changes the table from occupied to free
        private void SetTableFree(RestaurantTable table, SqlTransaction transaction)
        {
            string query = @"UPDATE [Restaurant_Table] SET is_occupied = 0
                            WHERE [Restaurant_Table].table_number = @table_number";

            SqlParameter[] sqlParameters = new SqlParameter[1] {
                new SqlParameter("@table_number", table.TableId)
            };

            ExecuteEditTranQuery(query, sqlParameters, transaction);
        }
 public void AddOrder(RestaurantTable table, Employee employee, List <OrderItem> orderItemList)
 {
     try
     {
         order_db.Db_Add_Order(table, employee, orderItemList);
     }
     catch (Exception e)
     {
         throw new Exception("Chapeau application couldn't connect to the database. Therefore we cannot add the orders data.");
     }
 }
Exemplo n.º 20
0
        public void AddTableByRestaurantId(RestaurantTable restaurantTable, int id)
        {
            Restaurant restaurant = _dbContext.Restaurants.FirstOrDefault(r => r.Id == id);

            if (restaurant.RestaurantTables == null)
            {
                restaurant.RestaurantTables = new List <RestaurantTable>();
            }
            restaurant.RestaurantTables.Add(restaurantTable);
            _dbContext.RestaurantTables.Add(restaurantTable);
            _dbContext.SaveChanges();
        }
Exemplo n.º 21
0
        public async Task <RestaurantTable> DeleteRestaurantTable(int restaurantTableId)
        {
            RestaurantTable dbEntry = dbContext.RestaurantTables.Find(restaurantTableId);

            if (dbEntry != null)
            {
                dbContext.RestaurantTables.Remove(dbEntry);
            }

            await dbContext.SaveChangesAsync();

            return(dbEntry);
        }
        public async Task <int> Post(RestaurantTable model)
        {
            var result = 0;

            if (ModelState.IsValid)
            {
                model.Status = 1;
                var modelInsert = await _restaurantTableBusiness.Add(model);

                result = modelInsert.Id;
            }
            return(result);
        }
        // GET: ARestaurantTables/Details/5
        public ActionResult Details(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RestaurantTable restaurantTable = userAppManager.FindRestaurantTable(id);

            if (restaurantTable == null)
            {
                return(HttpNotFound());
            }
            return(View(restaurantTable));
        }
Exemplo n.º 24
0
        //First constructor: This is used when the user requests this form to show only reservations to a specific RestaurantTable
        public ReservationsForm(RestaurantTable item, MainForm _master)
        {
            this._master = _master;
            InitializeComponent();

            lvBookings.Columns.Add("Customer Name", 180);
            lvBookings.Columns.Add("Taken From", 190);
            lvBookings.Columns.Add("Taken To", 190);
            lvBookings.Columns.Add("Booked By", 120);
            lvBookings.Columns.Add("Contact Number", 170);

            thisTable     = item;
            lblTitle.Text = thisTable.Name;

            populateList(true);
        }
Exemplo n.º 25
0
        /// <summary>
        /// get all tables of a restaurant
        /// </summary>
        /// <param name="RestaurantId">id</param>
        /// <returns>list of tables</returns>
        public List <RestaurantTable> GetAllTables(int RestaurantId)
        {
            Database db            = Database.Open(DatabaseName);
            string   insertCommand = "SELECT * FROM RestaurantTable WHERE RestaurantId = @0";
            var      rows          = db.Query(insertCommand, RestaurantId);

            db.Close();
            List <RestaurantTable> tables = new List <RestaurantTable>();

            foreach (var row in rows)
            {
                var table = new RestaurantTable(row.Id, row.RestaurantId, row.Available, row.TableNumber, row.NumberOfChairs);
                tables.Add(table);
            }
            return(tables);
        }
Exemplo n.º 26
0
        // Add new order to database
        private int Db_Add_New_Order(RestaurantTable table, Employee employee)
        {
            string query = @"
                INSERT INTO [Order] (table_number, employee_id, total_cost, tip, is_payed, feedback) 
                    VALUES(@table_number, @employee_id, 0, 0, 0, '') SELECT SCOPE_IDENTITY();";

            SqlParameter[] sqlParameters = new SqlParameter[2]
            {
                new SqlParameter("@table_number", table.TableId),
                new SqlParameter("@employee_id", employee.EmployeeId)
            };

            int autoIncrementId = ExecuteEditQueryAutoIncrement(query, sqlParameters);

            return(autoIncrementId);
        }
Exemplo n.º 27
0
        private List <RestaurantTable> ReadTables(DataTable dataTable)
        {
            List <RestaurantTable> restaurantTablesList = new List <RestaurantTable>();

            foreach (DataRow dr in dataTable.Rows)
            {
                RestaurantTable restaurantTables = new RestaurantTable(
                    (int)dr["table_number"],
                    (bool)dr["is_occupied"],
                    (int)dr["number_of_seats"]
                    );

                restaurantTablesList.Add(restaurantTables);
            }
            return(restaurantTablesList);
        }
Exemplo n.º 28
0
 public async Task <RestaurantTable> CreateTable(Guid restaurantId, [FromBody] RestaurantTable table)
 {
     if (table == null)
     {
         return(null);
     }
     try
     {
         var proxy = new RestaurantServiceProxyFactory().CreateAdminServiceProxy();
         return(await proxy.CreateTable(restaurantId, table));
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
     return(null);
 }
        public async Task <bool> Update(RestaurantTable model)
        {
            var result = false;
            var record = await _restaurantTableRepository.Repo.FirstOrDefaultAsync(c => c.Id == model.Id);

            if (record != null)
            {
                record.Name        = model.Name;
                record.Capacity    = model.Capacity;
                record.Location    = model.Location;
                record.Description = model.Description;

                await _restaurantTableRepository.SaveChangeAsync();

                result = true;
            }
            return(result);
        }
Exemplo n.º 30
0
        public TakeOrder(Employee employee, RestaurantTable table)
        {
            InitializeComponent();

            ShowCorrectPanel(1);

            flowLayoutPanelMenu.Controls.Clear();
            PopulateMenu();

            navigation.Hide();

            order_service = new Order_Service();
            this.employee = employee;
            this.table    = table;

            lbl_tableNumber.Text = table.TableId.ToString();
            lbl_ActiveMenu.Text  = "";
        }