Exemplo n.º 1
0
        private async void txtBtnSearch_Click(object sender, EventArgs e)
        {
            var search = new Model.Requests.Rent.RentSearchRequest();

            if (dtpEnd.Value.Date < dtpStart.Value.Date)
            {
                errorProvider1.SetError(dtpEnd, "End date can not be smaller then start date");
            }
            else
            {
                errorProvider1.Clear();
            }

            if (dtpStart.Value.Date < dtpEnd.Value.Date)
            {
                search.StartDate = dtpStart.Value.Date;
                search.EndDate   = dtpEnd.Value.Date;
            }
            if (!string.IsNullOrWhiteSpace(txtName.Text))
            {
                search.UserName = txtName.Text;
            }
            if (!string.IsNullOrWhiteSpace(txtVehicleName.Text))
            {
                search.VehicleName = txtVehicleName.Text;
            }

            var list = await _serviceRent.Get <List <Model.Rent> >(search);

            if (list == null || list.Count == 0)
            {
                MessageBox.Show("No result for that search query.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            await GetData(list);
        }
Exemplo n.º 2
0
        private async Task <bool> ValidateRent()
        {
            if (dtpEnd.Value.Date <= dtpFrom.Value.Date)
            {
                err.SetError(dtpEnd, "End date can not be in past or same as start day.");
                return(false);
            }
            else if (dtpFrom.Value.Date < DateTime.Now.Date)
            {
                err.SetError(dtpFrom, "Start day can not be in past.");
                return(false);
            }
            else
            {
                lblInfo.Visible = false;
                err.Clear();
                var request = new Model.Requests.Rent.RentSearchRequest()
                {
                    VehicleId = id,
                    EndDate   = dtpEnd.Value,
                    StartDate = dtpFrom.Value
                };
                var rent = await _serviceRentCheck.CheckAvailibility <List <Model.Rent> >(request);

                if (rent == null)
                {
                    lblNextTime.Visible          = false;
                    lblAvailableStatus.Visible   = true;
                    lblAvailableStatus.ForeColor = Color.Green;
                    lblAvailableStatus.Text      = "Available";
                    var days = (dtpEnd.Value.Date - dtpFrom.Value.Date).Days;
                    lblTotalPrice.Text    = "Total price is " + Math.Round((price * days), 2).ToString() + " BAM";
                    lblTotalPrice.Visible = true;
                    return(true);
                }
                else
                {
                    DateTime next = rent[0].EndDate;
                    for (int i = 0; i < rent.Count - 1; ++i)
                    {
                        if (next < rent[i + 1].EndDate)
                        {
                            next = rent[i + 1].EndDate;
                        }
                    }
                    lblNextTime.Visible          = true;
                    lblNextTime.Text             = "Available after: " + next.Date.ToString().Substring(0, 9);
                    lblAvailableStatus.Visible   = true;
                    lblAvailableStatus.ForeColor = Color.Red;
                    lblAvailableStatus.Text      = "Unavailable";
                    return(false);
                }
            }
        }
Exemplo n.º 3
0
        private async Task RentVehicle()
        {
            if (EndDate.Date < StartDate.Date)
            {
                await Application.Current.MainPage.DisplayAlert("Status", "End date can not be lower then start date.", "Try again");

                return;
            }
            if (EndDate.Date == StartDate.Date)
            {
                await Application.Current.MainPage.DisplayAlert("Status", "End date can not be same as start date.", "Try again");

                return;
            }
            var request = new Model.Requests.Rent.RentSearchRequest()
            {
                VehicleId = Vehicle.Id,
                EndDate   = EndDate.Date,
                StartDate = StartDate.Date
            };
            var rent = await _serviceCheck.CheckAvailibility <List <Rent> >(request);

            if (rent == null || rent.Count == 0)
            {
                RentStatus                 = "Available. Proceed to checkout.";
                RentAvailable              = true;
                RentButton                 = false;
                CheckoutService._vehicle   = Vehicle;
                CheckoutService._stardDate = StartDate;
                CheckoutService._endDate   = EndDate;
            }
            else
            {
                DateTime next = rent[0].EndDate;
                for (int i = 0; i < rent.Count - 1; ++i)
                {
                    if (next < rent[i + 1].EndDate)
                    {
                        next = rent[i + 1].EndDate;
                    }
                }
                RentStatus = "Available after " + next.Date.ToString().Substring(0, 9);
            }
        }
Exemplo n.º 4
0
        private async void GetData(List <Model.Rent> rentList = null)
        {
            if (id == 0)
            {
                await GetCity();
                await GetRole();

                txtUsername.ReadOnly = false;
                chActive.Checked     = true;
            }
            else
            {
                txtPassword.Visible  = false;
                txtPwConfirm.Visible = false;
                if (APIService.loggedUser.RoleId == 2)
                {
                    cbRole.Enabled   = false;
                    chActive.Enabled = false;
                }
                if (dgvRents.Columns.Contains("btnReview"))
                {
                    dgvRents.Columns.Remove("btnReview");
                }

                if (dgvRents.Columns.Contains("btnCancel"))
                {
                    dgvRents.Columns.Remove("btnCancel");
                }
                var userreq = new Model.Requests.User.UserSearchRequest()
                {
                    UserId = id
                };
                var user = await _userService.Get <List <Model.User> >(userreq);

                var rentreq = new Model.Requests.Rent.RentSearchRequest()
                {
                    UserId = id
                };

                if (rentList != null)
                {
                    rents = rentList;
                }
                else
                {
                    rents = await _rentService.Get <List <Model.Rent> >(rentreq);
                }
                var dgvList = new List <Model.ViewModel.UserDetailsVM>();


                foreach (var rent in rents)
                {
                    var dgvItem = new Model.ViewModel.UserDetailsVM()
                    {
                        RentId      = rent.Id,
                        VehicleName = rent.Vehicle.Name.ToString(),
                        fromDate    = rent.StartDate.ToString(),
                        ToDate      = rent.EndDate.ToString(),
                        DateCreated = rent.DateCreated.ToString(),
                        Status      = (rent.IsReviewed == true ? "Reviewed" : "Not reviewed")
                    };
                    if (rent.IsCanceled)
                    {
                        dgvItem.Status = "Canceled";
                    }
                    dgvList.Add(dgvItem);
                }

                txtFirstName.Text = user[0].FirstName.ToString();
                txtLastName.Text  = user[0].LastName.ToString();
                txtUsername.Text  = user[0].Username.ToString();
                txtEmail.Text     = user[0].Email.ToString();
                txtPhone.Text     = user[0].Phone.ToString();
                await GetCity();
                await GetRole();

                cbCity.SelectedIndex = user[0].CityId;
                cbRole.SelectedIndex = user[0].RoleId;
                chActive.Checked     = user[0].Active;

                dgvRents.DataSource         = dgvList;
                dgvRents.Columns[0].Visible = false;

                DataGridViewButtonColumn bcol = new DataGridViewButtonColumn();
                bcol.HeaderText = "Action";
                bcol.Text       = "Review";
                bcol.Name       = "btnReview";
                bcol.UseColumnTextForButtonValue = true;

                DataGridViewButtonColumn bcol2 = new DataGridViewButtonColumn();
                bcol2.HeaderText = "Action";
                bcol2.Text       = "Cancel";
                bcol2.Name       = "btnCancel";
                bcol2.UseColumnTextForButtonValue = true;

                if (!dgvRents.Columns.Contains("btnReview") && id == APIService.loggedUser.Id)
                {
                    dgvRents.Columns.Add(bcol);
                }
                if (!dgvRents.Columns.Contains("btnCancel") && id == APIService.loggedUser.Id)
                {
                    dgvRents.Columns.Add(bcol2);
                }
                if (dgvRents.RowCount > 0)
                {
                    btnReport.Visible = true;
                }
            }
        }
Exemplo n.º 5
0
        private async Task GetData(List <Model.User> users = null)
        {
            List <Model.User> list;

            if (dgvUserList.Columns.Contains("btnDetails"))
            {
                dgvUserList.Columns.Remove("btnDetails");
            }

            if (users == null)
            {
                list = await _userService.Get <List <Model.User> >();
            }
            else
            {
                list = users;
            }

            var gridList     = new List <Model.ViewModel.UserListVM>();
            int activeNumber = 0;

            foreach (var item in list)
            {
                var request = new Model.Requests.Rent.RentSearchRequest()
                {
                    UserId        = item.Id,
                    UserRentCount = true
                };

                if (item.Active)
                {
                    activeNumber++;
                }
                var number = await _rentService.Get <List <Model.Rent> >(request);

                var gridItem = new Model.ViewModel.UserListVM()
                {
                    Name          = item.FirstName.ToString() + " " + item.LastName.ToString(),
                    Contact       = item.Email,
                    NumberOfRents = number.Count,
                    Role          = item.Role.Name.ToString(),
                    Status        = (item.Active == true ? "Active" : "Disabled"),
                    UserId        = item.Id
                };

                gridList.Add(gridItem);
            }
            DataGridViewButtonColumn bcol = new DataGridViewButtonColumn();

            bcol.HeaderText = "Action";
            bcol.Text       = "Details";
            bcol.Name       = "btnDetails";

            dgvUserList.DataSource         = gridList;
            dgvUserList.Columns[0].Visible = false;

            bcol.UseColumnTextForButtonValue = true;
            if (!dgvUserList.Columns.Contains("btnDetails"))
            {
                dgvUserList.Columns.Add(bcol);
            }

            lblActive.Text       = "Active users: " + activeNumber.ToString();
            lblNumberOfRows.Text = "Number of rows: " + list.Count.ToString();
        }