Esempio n. 1
0
        private async void frmAddReview_Load(object sender, EventArgs e)
        {
            rent = await _rentService.GetById <Model.Rent>(rentId);

            var req = new Model.Requests.Review.ReviewSearchRequest()
            {
                VehicleId = rent.VehicleId
            };
            var review = await _reviewService.Get <List <Model.Review> >(req);

            double rating = 0;

            if (review.Count > 0)
            {
                rating = review.Average(x => x.NumberOfStars);
            }

            lblVehicle.Text += " " + rent.Vehicle.Name;
            lblRating.Text   = Math.Round(rating, 1).ToString() + " average score";
            lblCount.Text    = review.Count.ToString() + " review(s)";
        }
Esempio n. 2
0
        private async void frmAddVehicle_Load(object sender, EventArgs e)
        {
            btnDelete.Visible = false;
            if (APIService.loggedUser.RoleId == 2)
            {
                btnDelete.Visible = false;
                if (editVehicle != null)
                {
                    LockControlValues(this);
                    btnImage.Visible    = false;
                    btnSave.Text        = "Rent";
                    btnAddModel.Visible = false;
                }
            }
            pictureBox1.Image = null;
            if (EditId != 0)
            {
                if (APIService.loggedUser.RoleId == 1)
                {
                    btnDelete.Visible = true;
                }
                try
                {
                    editVehicle = await _serviceVehicle.GetById <Model.Vehicle>(EditId);
                }
                catch (Exception)
                {
                    MessageBox.Show("Vehicle could not be found", "Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw;
                }
                txtName.Text     = editVehicle.Name;
                txtPrice.Text    = editVehicle.Price.ToString();
                txtSeats.Text    = editVehicle.NumberOfSeats.ToString();
                txtYear.Text     = editVehicle.YearManufactured.ToString();
                rtxtDesc.Text    = editVehicle.Description;
                cbActive.Checked = editVehicle.IsActive.Value;
                if (editVehicle.Image.Length > 0)
                {
                    pictureBox1.Image = GetImage(editVehicle.Image);
                }
                await GetBrand();
                await GetFuel();
                await GetModel();

                GetTransmission();
                cmbFuel.SelectedIndex  = editVehicle.Fuel.Id;
                cmbModel.SelectedIndex = editVehicle.VehicleModel.Id;
                cmbBrand.SelectedIndex = editVehicle.Brand.Id;

                var reviewsRequest = new Model.Requests.Review.ReviewSearchRequest()
                {
                    VehicleId = EditId
                };

                var reviewList = await _reviewVehicle.Get <List <Model.Review> >(reviewsRequest);

                var dgvList = new List <Model.ViewModel.ReviewListVM>();
                foreach (var item in reviewList)
                {
                    Model.ViewModel.ReviewListVM vm = new Model.ViewModel.ReviewListVM()
                    {
                        Comment       = item.Comment,
                        DatePosted    = item.DatePosted.ToString(),
                        NumberOfStars = item.NumberOfStars.ToString(),
                        Username      = item.User.Username
                    };
                    dgvList.Add(vm);
                }
                dgvReviews.DataSource            = dgvList;
                dgvReviews.Columns[1].HeaderText = "Rating";
                dgvReviews.Columns[3].HeaderText = "Date commented";

                if (dgvList.Count > 0)
                {
                    lblNoReviews.Text    = "Number of reviews: " + reviewList.Count.ToString();
                    lblAverageScore.Text = "Score " + Math.Round(reviewList.Average(x => x.NumberOfStars), 2).ToString();
                }

                if (editVehicle.Transmission.StartsWith("Automatic"))
                {
                    cbTransmission.SelectedIndex = 1;
                }
                else if (editVehicle.Transmission.StartsWith("Manual"))
                {
                    cbTransmission.SelectedIndex = 2;
                }
                else
                {
                    cbTransmission.SelectedIndex = 0;
                }


                FavoriteCheck();
            }
            else
            {
                btnFavorites.Visible = false;
                await GetFuel();
                await GetBrand();
                await GetModel();

                GetTransmission();
            }
        }