Exemplo n.º 1
0
 public void Save(CarRent carRent)
 {
     if (carRent != null)
     {
         _carsRent.Add(carRent);
     }
 }
Exemplo n.º 2
0
        public IHttpActionResult PutCarRent(int id, CarRent carRent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != carRent.DocId)
            {
                return(BadRequest());
            }

            db.Entry(carRent).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarRentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            CarRent carRent = _carRentsRepository.GetWhere(i => i.Id == id).FirstOrDefault();

            _carRentsRepository.Delete(carRent);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public IHttpActionResult PostCarRent(CarRent carRent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CarRents.Add(carRent);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CarRentExists(carRent.DocId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = carRent.DocId }, carRent));
        }
Exemplo n.º 5
0
 public ActionResult Edit(CarRent carRent)
 {
     if (ModelState.IsValid)
     {
         _carRentsRepository.Edit(carRent);
         return(RedirectToAction("Index"));
     }
     return(View(carRent));
 }
Exemplo n.º 6
0
        public ActionResult Approve(CarRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarRent carRent = db.CarRental.Find(model.Id);

            carRent.Status = CarRent.StatusEnum.Approved;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        public IHttpActionResult DeleteCarRent(int id)
        {
            CarRent carRent = db.CarRents.Find(id);

            if (carRent == null)
            {
                return(NotFound());
            }

            db.CarRents.Remove(carRent);
            db.SaveChanges();

            return(Ok(carRent));
        }
Exemplo n.º 8
0
        // GET: CarRents/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarRent carRent = _carRentsRepository.GetWhere(i => i.Id == id.Value).FirstOrDefault();

            if (carRent == null)
            {
                return(HttpNotFound());
            }
            return(View(carRent));
        }
Exemplo n.º 9
0
        //Delete Get
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
            }
            CarRent carRent = db.CarRental.Find(id);
            var     model   = getVMFromCarRent(carRent);

            if (model == null)
            {
                return(HttpNotFound());
            }

            return(View(model));
        }
Exemplo n.º 10
0
        public async Task <IdentityResult> SendRentConfirmationMail(Person user, CarRent rent)
        {
            await Task.Yield();

            var fromMail           = new MailAddress("*****@*****.**");
            var frontEmailPassowrd = "bojan.pisic.123";

            var    toMail = new MailAddress(user.Email);
            string subject;
            string body;

            subject = "Your rent is successfull created.";
            body    = "<br/><br/>Your rent is created. Check your rents on your profile.<br/><br/>Reservation details: " +
                      "<br/><t/><t/>From: " + rent.TakeOverCity +
                      "<br/><t/><t/>To: " + rent.ReturnCity +
                      "<br/><t/><t/>Take over date: " + rent.TakeOverDate +
                      "<br/><t/><t/>Return date: " + rent.ReturnDate +
                      "<br/><br/>Car details<br/>" +
                      "<br/><t/><t/>Brand: " + rent.RentedCar.Brand +
                      "<br/><t/><t/>Model: " + rent.RentedCar.Model +
                      "<br/><t/><t/>Car type: " + rent.RentedCar.Type +
                      "<br/><t/><t/>Price per day: " + rent.RentedCar.PricePerDay + "$" +
                      "</br>Total price: " + rent.TotalPrice + "$" +
                      "<br/><t/><t/>"
                      + "<br/><br/> SkyRoads";

            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(fromMail.Address, frontEmailPassowrd)
            };

            using (var message = new MailMessage(fromMail, toMail)
            {
                Subject = subject,
                Body = body,
                IsBodyHtml = true
            })
                smtp.Send(message);

            return(IdentityResult.Success);
        }
Exemplo n.º 11
0
        public ResponseMessage <CarRent> SaveCarRent([FromBody] CarRent carRent)
        {
            ResponseMessage <CarRent> response = new ResponseMessage <CarRent>();

            try
            {
                this._carRenRepository.Save(carRent);
                response.Status = HttpStatusCode.OK;
                return(response);
            }
            catch (Exception ex)
            {
                response.Status = HttpStatusCode.InternalServerError;
                //_loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now });
            }
            return(response);
        }
Exemplo n.º 12
0
        public ActionResult Decline(CarRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarRent carRent = db.CarRental.Find(model.Id);

            carRent.Status = CarRent.StatusEnum.Rejected;

            Car carInDb = db.Cars.Find(carRent.CarId);

            carInDb.Availability += 1;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 13
0
 public ActionResult Save(CarRent rent)
 {
     if (ModelState.IsValid)
     {
         db.CarRents.Add(rent);
         var car = db.CarRegisters.SingleOrDefault(e => e.CarNum == rent.CarId);
         if (car == null)
         {
             return(HttpNotFound("Entered car number is Invalid"));
         }
         car.Available       = "no";
         db.Entry(car).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rent));
 }
Exemplo n.º 14
0
        public ActionResult DeleteConfirmed(int Id)
        {
            if (Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarRent carRent = db.CarRental.Find(Id);
            var     carInDb = db.Cars.Where(b => b.Id.Equals(carRent.CarId)).FirstOrDefault();

            if (!carRent.Status.ToString().Equals("Rented"))
            {
                carInDb.Availability += 1;
            }
            db.CarRental.Remove(carRent);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 15
0
        public void ProcessInvoice(CarRent carRent, Vehicle vehicle)
        {
            TimeSpan duration = carRent.Finish.Subtract(carRent.Start);

            double basicPayment = 0.0;

            if (duration.TotalHours <= 12.0)
            {
                basicPayment = vehicle.PriceHour * Math.Ceiling(duration.TotalHours);
            }
            else
            {
                basicPayment = vehicle.PriceOfDay * Math.Ceiling(duration.TotalDays);
            }

            double tax = _taxService.Tax(basicPayment);

            carRent.Invoice = new Invoice(basicPayment, tax);
        }
Exemplo n.º 16
0
        public ActionResult Reserve(CarRentalViewModel car)
        {
            var    userid    = User.Identity.GetUserId();
            Car    carToRent = db.Cars.Find(car.CarId);
            double rentalPr  = 0;

            if (userid != null)
            {
                var chargeRate = from u in db.Users
                                 join m in db.MembershipTypes
                                 on u.MembershipTypeId equals m.Id
                                 where u.Id.Equals(userid)
                                 select new { m.ChargeRateOneMonth, m.ChargeRateTwoMonth };
                if (car.RentalDuration == SD.TwoMonthCount)
                {
                    rentalPr = Convert.ToDouble(carToRent.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateTwoMonth) / 100;
                }
                else
                {
                    rentalPr = Convert.ToDouble(carToRent.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateOneMonth) / 100;
                }

                CarRent carRent = new CarRent
                {
                    CarId          = carToRent.Id,
                    UserId         = userid,
                    RentalDuration = car.RentalDuration,
                    RentalPrice    = rentalPr,

                    Status = CarRent.StatusEnum.Requested,
                };

                db.CarRental.Add(carRent);
                var carInDb = db.Cars.SingleOrDefault(c => c.Id == car.CarId);

                carInDb.Availability -= 1;

                db.SaveChanges();
                return(RedirectToAction("Index", "CarRent"));
            }
            return(View());
        }
Exemplo n.º 17
0
        public ActionResult RegisterNewCarRent(CarRent rent, string Button)
        {
            if (Button.Equals("Submit"))
            {
                Validations                 validation = new Validations();
                DatabaseRequests            request    = new DatabaseRequests();
                Tuple <List <string>, bool> value      = validation.ValidateCarRent(rent.Car.Plate, rent.Reservation.CustomerID.ToString(), rent.StartDate, rent.EndDate, rent.Reservation.Location);

                if (value.Item2)
                {
                    request.AddCarRentToDatabase(rent.Car.Plate, rent.Reservation.CustomerID.ToString(), DateTime.Parse(rent.StartDate), DateTime.Parse(rent.EndDate), rent.Reservation.Location);
                }
                else
                {
                    if (value.Item1[0] != "")
                    {
                        ModelState.AddModelError("Plate", value.Item1[0]);
                    }
                    if (value.Item1[1] != "")
                    {
                        ModelState.AddModelError("CustomerID", value.Item1[1]);
                    }
                    if (value.Item1[2] != "")
                    {
                        ModelState.AddModelError("StartDate", value.Item1[2]);
                    }
                    if (value.Item1[3] != "")
                    {
                        ModelState.AddModelError("EndDate", value.Item1[3]);
                    }
                    if (value.Item1[4] != "")
                    {
                        ModelState.AddModelError("Location", value.Item1[4]);
                    }

                    return(View("RegisterNewCarRent"));
                }
            }

            return(View("Menu"));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Calculating cost for renting specifc car for certain time
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            if (lbCars.SelectedIndex != -1)
            {
                Car     car   = cars[lbCars.SelectedIndex];
                decimal hours = numHours.Value;

                CarRent rent = new CarRent();
                rent.Car          = car;
                rent.Hours        = hours;
                rent.PricePerHour = car.Year;

                decimal cost = objService.calculateCost(rent);

                tbResult.Text = string.Format("It will cost you: {0:0.0}", cost);
            }
            else
            {
                tbResult.Text = "Please select a car";
            }
        }
Exemplo n.º 19
0
        public ActionResult Return(CarRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarRent carRent = db.CarRental.Find(model.Id);

            carRent.Status           = CarRent.StatusEnum.Closed;
            carRent.AdditionalCharge = model.AdditionalCharge;

            Car carInDb = db.Cars.Find(carRent.CarId);

            carInDb.Availability += 1;

            carRent.ActualEndDate = DateTime.Now;

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Edit([Bind("CarRentID,ClientID,CarModel,StartDate,EndDate,City")] CarRent carRent)
        {
            if (ModelState.IsValid)
            {
                DateTime startDate    = carRent.StartDate;
                DateTime endDate      = carRent.EndDate;
                int      clientIDEdit = carRent.ClientID;

                if (startDate > endDate || clientIDEdit == 0)
                {
                    return(RedirectToAction(nameof(Edit)));
                }
                else
                {
                    _context.Update(carRent);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(carRent));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Method for generating reservations
        /// </summary>
        private void generateReservation()
        {
            CarRent e1 = new CarRent(cars[0], 12);
            CarRent e2 = new CarRent(cars[0], 48);
            CarRent e3 = new CarRent(cars[0], 48);
            CarRent e4 = new CarRent(cars[1], 36);
            CarRent e5 = new CarRent(cars[1], 12);
            CarRent e6 = new CarRent(cars[2], 64);
            CarRent e7 = new CarRent(cars[2], 48);
            CarRent e8 = new CarRent(cars[3], 6);
            CarRent e9 = new CarRent(cars[3], 12);

            reservations.Add(e1);
            reservations.Add(e2);
            reservations.Add(e3);
            reservations.Add(e4);
            reservations.Add(e5);
            reservations.Add(e6);
            reservations.Add(e7);
            reservations.Add(e8);
            reservations.Add(e9);
        }
Exemplo n.º 22
0
        public ActionResult PickUp(CarRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarRent carRent = db.CarRental.Find(model.Id);

            carRent.Status    = CarRent.StatusEnum.Rented;
            carRent.StartDate = DateTime.Now;
            if (carRent.RentalDuration == SD.TwoMonthCount)
            {
                carRent.ScheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.TwoMonthCount));
            }
            else
            {
                carRent.ScheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.OneMonthCount));
            }
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 23
0
        private CarRentalViewModel getVMFromCarRent(CarRent carRent)
        {
            Car carSelected = db.Cars.Where(b => b.Id == carRent.CarId).FirstOrDefault();
            var userDetails = from u in db.Users
                              where u.Id.Equals(carRent.UserId)
                              select new { u.Id, u.FirstName, u.LastName, u.Email };

            CarRentalViewModel model = new CarRentalViewModel
            {
                Id          = carRent.Id,
                CarId       = carSelected.Id,
                RentalPrice = carRent.RentalPrice,
                Price       = carSelected.Price,
                Seats       = carSelected.Seats,
                FirstName   = userDetails.ToList()[0].FirstName,
                LastName    = userDetails.ToList()[0].LastName,
                //BirthDate = userDetails.ToList()[0].bir
                Email            = userDetails.ToList()[0].Email,
                UserId           = userDetails.ToList()[0].Id,
                ScheduledEndDate = carRent.ScheduledEndDate,
                Manufacturer     = carSelected.Manufacturer,
                StartDate        = carRent.StartDate,
                Availability     = carSelected.Availability,
                DateAdded        = carSelected.DateAdded,
                Description      = carSelected.Description,
                TypeId           = carSelected.TypeId,
                Type             = db.TypeCars.FirstOrDefault(g => g.Id.Equals(carSelected.TypeId)),
                Rego             = carSelected.Rego,
                ImageUrl         = carSelected.ImageUrl,
                FuelType         = carSelected.FuelType,
                Engine           = carSelected.Engine,
                RentalDuration   = carRent.RentalDuration,
                Status           = carRent.Status.ToString(),
                Brand            = carSelected.Brand,
                AdditionalCharge = carRent.AdditionalCharge,
            };

            return(model);
        }
Exemplo n.º 24
0
        void RentCarButton_Click(Object sender, EventArgs e)
        {
            Int32.TryParse(CountOfDaysBox.Text, NumberStyles.Any, null, out Int32 countOfDays);

            try {
                DataGridViewSelectedRowCollection rows = FreeCarGridView.SelectedRows;
                if (rows.Count == 0 || countOfDays == 0 || !(rows[0].DataBoundItem is CarEntity car))
                {
                    return;
                }

                var carRent = new CarRent {
                    CarID        = car.ID,
                    ClientID     = _client.ID,
                    LeaseStarted = DateTime.Now,
                    LeaseEnded   = DateTime.Now.AddDays(Convert.ToInt32(CountOfDaysBox.Text))
                };
                _mgr.RentCar(carRent);
                RefreshTables();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Rent Car Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 25
0
 public void Update(CarRent carRent)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 26
0
        // GET: UpdateCarRent
        public ActionResult UpdateCarRent(CarRent rent, string Button)
        {
            Validations      validation = new Validations();
            DatabaseRequests request    = new DatabaseRequests();
            Reservation      initialRes = new Reservation();
            string           error      = "";

            if (Button.Equals("Search"))
            {
                if (validation.DateValidation(rent.StartDate) == "")
                {
                    error = request.GetRentForUpdate(rent.Car.Plate, rent.Reservation.CustomerID.ToString(), rent.StartDate, rent);
                }
                else
                {
                    error = request.GetRentForUpdate(rent.Car.Plate, rent.Reservation.CustomerID.ToString(), rent.StartDate, rent);
                }

                if (error == "/")
                {
                    initialRes           = rent.Reservation;
                    initialRes.StartDate = DateTime.Parse(rent.StartDate);
                }
                else if (error.Contains("/"))
                {
                    string[] errors = error.Split('/');

                    if (errors[0] != "")
                    {
                        ModelState.AddModelError("CustomerID", errors[0]);
                    }
                    if (errors[1] != "")
                    {
                        ModelState.AddModelError("Plate", errors[1]);
                    }
                }
                else
                {
                    ModelState.AddModelError("Plate", error);
                }
            }
            else if (Button.Equals("Delete"))
            {
                if (initialRes.Location != "")
                {
                    error = request.DeleteRent(rent.Car.Plate, rent.Reservation.CustomerID.ToString(), Button, initialRes);
                }
            }
            else if (Button.Equals("Update"))
            {
                Tuple <List <string>, bool> value = validation.ValidateCarRent(rent.Car.Plate, rent.Reservation.CustomerID.ToString(), rent.StartDate, rent.EndDate, rent.Reservation.Location);
                if (value.Item2)
                {
                    request.UpdateCarRentInDatabase(rent.Car.Plate, rent.Reservation.CustomerID.ToString(), DateTime.Parse(rent.StartDate), DateTime.Parse(rent.EndDate), rent.Reservation.Location, initialRes);
                }
                else
                {
                    if (value.Item1[0] != "")
                    {
                        ModelState.AddModelError("Plate", value.Item1[0]);
                    }
                    if (value.Item1[1] != "")
                    {
                        ModelState.AddModelError("CustomerID", value.Item1[1]);
                    }
                    if (value.Item1[2] != "")
                    {
                        ModelState.AddModelError("StartDate", value.Item1[2]);
                    }
                    if (value.Item1[3] != "")
                    {
                        ModelState.AddModelError("EndDate", value.Item1[3]);
                    }
                    if (value.Item1[4] != "")
                    {
                        ModelState.AddModelError("Location", value.Item1[4]);
                    }
                }
            }
            else
            {
                return(View("Menu"));
            }

            return(View("UpdateCarRent", rent));
        }
Exemplo n.º 27
0
 static void Main(string[] args)
 {
     CarRent rt = new CarRent(CarGenerator(100));
 }
Exemplo n.º 28
0
 /// <summary>
 /// User frendly presentaon for reservation
 /// </summary>
 /// <param name="car">car rent</param>
 /// <returns>reservation in string format</returns>
 private string carRentToString(CarRent carRent)
 {
     return(string.Format("{0} {1:0.0} x {2:0.0} = {3:0.0}", carRent.Car.Registration, carRent.Hours, carRent.PricePerHour, carRent.Hours * carRent.PricePerHour));
 }
Exemplo n.º 29
0
 public CarRentViewModel(CarRent rent)
 {
     _rent        = rent;
     LeaseStarted = rent.LeaseStarted;
     LeaseEnded   = rent.LeaseEnded;
 }
Exemplo n.º 30
0
        public ActionResult Create(CarRentalViewModel carRent)
        {
            if (ModelState.IsValid)
            {
                var email = carRent.Email;

                var userDetails = from u in db.Users
                                  where u.Email.Equals(email)
                                  select new { u.Id, u.FirstName, u.LastName, u.BirthDate };

                var Rego = carRent.Rego;

                Car carSelected = db.Cars.Where(b => b.Rego == Rego).FirstOrDefault();

                var rentalDuration = carRent.RentalDuration;

                var chargeRate = from u in db.Users
                                 join m in db.MembershipTypes
                                 on u.MembershipTypeId equals m.Id
                                 where u.Email.Equals(email)
                                 select new { m.ChargeRateOneMonth, m.ChargeRateTwoMonth };

                var oneMonthRental = Convert.ToDouble(carSelected.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateOneMonth) / 100;
                var TwoMonthRental = Convert.ToDouble(carSelected.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateTwoMonth) / 100;

                double rentalPr = 0;

                if (carRent.RentalDuration == SD.TwoMonthCount)
                {
                    rentalPr = TwoMonthRental;
                }
                else
                {
                    rentalPr = oneMonthRental;
                }

                //BookRentalViewModel model = new BookRentalViewModel
                //{
                //    BookId = bookSelected.Id,
                //    RentalPrice = rentalPr,
                //    Price = bookSelected.Price,
                //    Pages = bookSelected.Pages,
                //    FirstName = userDetails.ToList()[0].FirstName,
                //    LastName = userDetails.ToList()[0].LastName,
                //    BirthDate = userDetails.ToList()[0].BirthDate,
                //    ScheduledEndDate = bookRent.ScheduledEndDate,
                //    Author = bookSelected.Author,
                //    Avaibility = bookSelected.Avaibility,
                //    DateAdded = bookSelected.DateAdded,
                //    Description = bookSelected.Description,
                //    Email = email,
                //    GenreId = bookRent.GenreId,
                //    Genre = db.Genres.Where(g => g.Id.Equals(bookSelected.GenreId)).First(),
                //    ISBN = bookSelected.ISBN,
                //    ImageUrl = bookSelected.ImageUrl,
                //    ProductDimensions = bookSelected.ProductDimensions,
                //    PublicationDate = bookSelected.PublicationDate,
                //    Publisher = bookSelected.Publisher,
                //    RentalDuration = bookRent.RentalDuration,
                //    Status = BookRent.StatusEnum.Requested.ToString(),
                //    Title = bookSelected.Title,
                //    UserId = userDetails.ToList()[0].Id,
                //    RentalPriceOneMonth = oneMonthRental,
                //    RentalPriceSixMonth = sixMonthRental
                //};

                CarRent modelToAddToDb = new CarRent
                {
                    CarId            = carSelected.Id,
                    RentalPrice      = rentalPr,
                    ScheduledEndDate = carRent.ScheduledEndDate,
                    RentalDuration   = carRent.RentalDuration,
                    Status           = CarRent.StatusEnum.Approved,
                    UserId           = userDetails.ToList()[0].Id
                };

                carSelected.Availability -= 1;
                db.CarRental.Add(modelToAddToDb);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View());
        }