// GET api/<controller>/5
        public IHttpActionResult Get(int id)
        {
            using (var rentalTransactionsBusiness = new RentalTransactionsBusiness())
            {
                RentalTransactions        rentalTransaction  = rentalTransactionsBusiness.SelectRentalTransactionleById(id);
                List <RentalTransactions> rentalTransactions = new List <RentalTransactions>();
                rentalTransactions.Add(rentalTransaction);

                var content = new ResponseContent <RentalTransactions>(rentalTransactions);

                return(new StandartResult <RentalTransactions>(content, Request));
            }
        }
 public bool UpdateRentalTransaction(RentalTransactions rentalTransactions)
 {
     try
     {
         bool isSuccess;
         using (var repo = new RentalTransactionsRepository())
         {
             isSuccess = repo.Update(rentalTransactions);
         }
         return(isSuccess);
     }
     catch (Exception ex)
     {
         throw new Exception("BusinessLogic:RentalTransactionsBusiness::UpdateRentalTransaction::Error occured.", ex);
     }
 }
        // POST api/<controller>
        public IHttpActionResult Post([FromBody] RentalTransactions rentalTransactions)
        {
            var content = new ResponseContent <RentalTransactions>(null);

            if (rentalTransactions != null)
            {
                using (var rentalTransactionsBusiness = new RentalTransactionsBusiness())
                {
                    content.Result = rentalTransactionsBusiness.InsertRentalTransaction(rentalTransactions) ? "1" : "0";

                    return(new StandartResult <RentalTransactions>(content, Request));
                }
            }

            content.Result = "0";

            return(new StandartResult <RentalTransactions>(content, Request));
        }
        // PUT api/<controller>/5
        public IHttpActionResult Put(int id, [FromBody] RentalTransactions rentalTransactions)
        {
            var content = new ResponseContent <RentalTransactions>(null);

            if (rentalTransactions != null)
            {
                using (var rentalTransactionsBusiness = new RentalTransactionsBusiness())
                {
                    rentalTransactions.RentalID = id;
                    content.Result = rentalTransactionsBusiness.UpdateRentalTransaction(rentalTransactions) ? "1" : "0";

                    return(new StandartResult <RentalTransactions>(content, Request));
                }
            }

            content.Result = "0";

            return(new StandartResult <RentalTransactions>(content, Request));
        }
        public bool InsertRentalTransaction(RentalTransactions entity)
        {
            try
            {
                bool isSuccess;
                using (var repo = new RentalTransactionsRepository())
                {
                    isSuccess = repo.Insert(entity);

                    /*using (var vehicleRepo = new VehiclesRepository())
                     * {
                     *  Vehicles v = vehicleRepo.SelectedById(entity.VehicleID);
                     *  generalRentalTransaction = v.RentalTransaction.ElementAt(v.RentalTransaction.Count - 1);
                     * }*/
                }
                return(isSuccess);
            }
            catch (Exception ex)
            {
                throw new Exception("BusinessLogic:RentalTransactionsBusiness::InsertRentalTransaction::Error occured.", ex);
            }
        }
Ejemplo n.º 6
0
        private async void BtnRent_Click(object sender, EventArgs e)
        {
            try
            {
                bool success = false;
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:54300/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    RentalTransactions rentalTransaction = new RentalTransactions()
                    {
                        PersonID  = _usernameSession.PersonID,
                        VehicleID = (int)dataGVRentingVehicle.CurrentRow.Cells["VehicleID"].Value
                    };

                    Vehicles vehicle = new Vehicles()
                    {
                        VehicleID    = (int)dataGVRentingVehicle.CurrentRow.Cells["VehicleID"].Value,
                        CompanyID    = (int)dataGVRentingVehicle.CurrentRow.Cells["CompanyID"].Value,
                        VehicleBrand = (string)dataGVRentingVehicle.CurrentRow.Cells["VehicleBrand"].Value,
                        VehicleModel = (string)dataGVRentingVehicle.CurrentRow.Cells["VehicleModel"].Value,
                        RequiredAgeOfDrivingLicense  = (int)dataGVRentingVehicle.CurrentRow.Cells["RequiredAgeOfDrivingLicense"].Value,
                        MinimumAgeLimit              = (int)dataGVRentingVehicle.CurrentRow.Cells["MinimumAgeLimit"].Value,
                        DailyKilometerLimit          = (int)dataGVRentingVehicle.CurrentRow.Cells["DailyKilometerLimit"].Value,
                        InstantKilometerOfTheVehicle = (int)dataGVRentingVehicle.CurrentRow.Cells["InstantKilometerOfTheVehicle"].Value,
                        Airbag         = (bool)dataGVRentingVehicle.CurrentRow.Cells["Airbag"].Value,
                        BaggageVolume  = (int)dataGVRentingVehicle.CurrentRow.Cells["BaggageVolume"].Value,
                        NumberOfSeats  = (int)dataGVRentingVehicle.CurrentRow.Cells["NumberOfSeats"].Value,
                        DailyRentPrice = (decimal)dataGVRentingVehicle.CurrentRow.Cells["DailyRentPrice"].Value,
                        LeasingStatus  = true
                    };

                    rentalTransaction.Vehicles.Add(vehicle);

                    UpdateVehicle(vehicle);

                    var serializedProduct = JsonConvert.SerializeObject(rentalTransaction);
                    var content           = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
                    var result            = await client.PostAsync("api/RentalTransaction", content);

                    if (result.IsSuccessStatusCode)
                    {
                        success = true;
                    }

                    if (success)
                    {
                        MessageBox.Show("Renting successful.");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Something went wrong. Please try again.");
                    }
                    ListVehicles();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error happened : " + ex.Message);
            }
        }