Beispiel #1
0
        public async Task <bool> AddCompany(CarCompany carCompany)
        {
            try
            {
                var company = await _context.FindAsync <CarCompany>(carCompany.Id);

                if (company != null)
                {
                    return(false);
                }

                //var admin = _context.FindAsync<UserModel>(carCompany.Admin).Result;

                await _context.AddAsync(company);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
                return(false);
            }
        }
        public async Task <IActionResult> AddBranchOffice(BranchOfficeForm branchOffices)
        {
            BranchOffices bo = new BranchOffices()
            {
                Name      = branchOffices.Name,
                Address   = branchOffices.Address,
                City      = branchOffices.City,
                Telephone = branchOffices.Telephone.ToString()
            };

            CarCompany carCompany = new CarCompany();

            carCompany = context.Carcompanies.Find(branchOffices.IdCompany);

            bo.Id_company = carCompany;



            context.BranchOffices.Add(bo);

            await context.SaveChangesAsync();

            context.Entry(carCompany).State = EntityState.Modified;

            return(Ok());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CarCompany carCompany = db.CarCompanies.Find(id);

            db.CarCompanies.Remove(carCompany);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <object> AddCompany([FromBody] CarCompany model)
        {
            if (!await _repository.AddCompany(model))
            {
                return(BadRequest(new { message = $"Car company: {model.Name} already exists..." }));
            }

            return(Ok(new { message = "Car company created.", company = model }));
        }
 public ActionResult Edit([Bind(Include = "CompanyId,CompanyName")] CarCompany carCompany)
 {
     if (ModelState.IsValid)
     {
         db.Entry(carCompany).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(carCompany));
 }
        public ActionResult Create([Bind(Include = "CompanyId,CompanyName")] CarCompany carCompany)
        {
            if (ModelState.IsValid)
            {
                db.CarCompanies.Add(carCompany);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(carCompany));
        }
 public void EditCompany([FromBody] CarCompany carCompany)
 {
     try
     {
         _context.CarCompanies.Update(carCompany);
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error while updating car company: [{e.Message}]");
     }
 }
Beispiel #8
0
 public ActionResult Edit(string nameAr, string nameEn, string nameOr, int id)
 {
     using (ApplicationDbContext db = new Models.ApplicationDbContext())
     {
         CarCompany Car = db.CarCompanies.Where(a => a.ID == id).FirstOrDefault();
         Car.NameAR = nameAr;
         Car.NameEN = nameEn;
         Car.NameOR = nameOr;
         db.SaveChanges();
         return(Json(new { result = true }, JsonRequestBehavior.AllowGet));
     }
 }
        private static void AddCar()
        {
            using (var context = new DealershipContext())
            {
                var car = new CarCompany
                {
                    Id   = 1,
                    Name = "Chevy"
                };

                context.CarCompanies.Add(car);
                context.SaveChanges();
            }
        }
        // GET: CarCompanies/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarCompany carCompany = db.CarCompanies.Find(id);

            if (carCompany == null)
            {
                return(HttpNotFound());
            }
            return(View(carCompany));
        }
        public async Task <object> Update(string id, [FromBody] CarCompany model)
        {
            CarCompany company = await _repository.GetCompanyByEmail(id);

            try
            {
                await _repository.UpdateCarCompany(model);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR with updating a car company. -> {ex.Message}");
            }

            return(Ok(new { message = "Car company updated.", company = company }));
        }
        //[Authorize(Roles = "CarAdmin")]
        public async Task <object> Delete(long id)
        {
            CarCompany company = await _repository.GetCompany(id);

            try
            {
                await _repository.DeleteCompany(id);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR with deleting company. -> {ex.Message}");
            }


            return(Ok(new { message = "Car company deleted", company = company }));
        }
Beispiel #13
0
        public ActionResult Add(string nameAr, string nameEn, string nameOr)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                CarCompany Car = new CarCompany();
                Car.NameAR = nameAr;
                Car.NameEN = nameEn;
                Car.NameOR = nameOr;
                Car.Block  = false;
                Car.Delete = false;
                db.CarCompanies.Add(Car);

                db.SaveChanges();
                return(Json(new { result = true }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #14
0
        public async Task <Object> CreateCarCompany([FromBody] CarCompanyModel model)
        {
            var admin = await _userManager.FindByEmailAsync(model.Admin.Email);

            if (admin == null)
            {
                var adminModel = new UserModel()
                {
                    FirstName   = model.Admin.FirstName,
                    LastName    = model.Admin.LastName,
                    Email       = model.Admin.Email,
                    City        = model.Admin.City,
                    PhoneNumber = model.Admin.PhoneNumber,
                    Street      = model.Admin.Street,
                };

                model.Admin = adminModel;
            }

            //new company
            CarCompany carCompany = new CarCompany()
            {
                Admin       = admin.Email,
                Address     = model.Address,
                Cars        = new List <Car>(),
                City        = model.City,
                Description = model.Description,
                Name        = model.Name,
                Rating      = 0,
                Thumbnail   = "",
                Lat         = model.Lat,
                Lon         = model.Lon
            };


            try
            {
                _context.CarCompanies.Add(carCompany);
                await _context.SaveChangesAsync();
            }
            catch (DbException dex)
            {
                Console.WriteLine($"Error with creating new car company. -> {dex.Message}");
            }

            return(Ok(carCompany));
        }
 public void TestInitialize()
 {
     _carCompany = new CarCompany
     {
         Cars = new[] {
             new Car
             {
                 Brand      = "Saab",
                 Passengers = new[] {
                     new Person
                     {
                         Name = "Foo",
                         Age  = 10
                     }
                 }
             }
         }
     };
 }
        public async Task <IActionResult> AddCarCompany(CompanyRegister company)
        {
            CarCompany carCompany = new CarCompany()
            {
                Cars        = new List <Car>(),
                Name        = company.RegistrationNameService,
                Address     = company.Address,
                Description = company.Description
            };


            carCompany.Administrator = await userManager.FindByNameAsync(company.Email);

            context.Carcompanies.Add(carCompany);

            await context.SaveChangesAsync();

            return(Ok());
        }
        public async Task <ActionResult <IEnumerable <CarFromModel> > > SearchAvailableCar(FilterCar filterCar)
        {
            List <CarFromModel> carFromModels = new List <CarFromModel>();

            CarCompany cc = new CarCompany();

            var listCompany = context.BranchOffices.Include(x => x.Id_company).ToList().SingleOrDefault(x => x.Id == Int32.Parse(filterCar.Id));

            if (listCompany == null)
            {
                var company = context.Companies.Find(Int32.Parse(filterCar.Id));
                cc = (CarCompany)company;
            }
            else
            {
                cc = listCompany.Id_company;
            }



            var rezervacije = context.ReservationCar.ToList();

            List <ReservationCar> filterReservation = new List <ReservationCar>();

            var pom = context.Carcompanies.Include(x => x.Cars).ToList().SingleOrDefault(x => x.Id == cc.Id).Cars.ToList();


            //PROVERITI DA LI SU KOLA NA POPUSTU

            var listaVozilaNaPopustu = context.DiscountCars.ToList();

            foreach (var popust in listaVozilaNaPopustu)
            {
                foreach (var auto in pom)
                {
                    if (auto.Id == popust.carId)
                    {
                        var poredjenje1 = DateTime.Compare(filterCar.startDay, popust.StartDay);
                        var poredjenje2 = DateTime.Compare(filterCar.endDay, popust.StartDay);

                        if (poredjenje1 < 0 && poredjenje2 < 0)
                        {
                            continue;
                        }
                        else if (poredjenje1 > 0 && poredjenje2 > 0)
                        {
                            var poredjenje3 = DateTime.Compare(filterCar.startDay, popust.EndDay);
                            var poredjenje4 = DateTime.Compare(filterCar.endDay, popust.EndDay);

                            if (poredjenje3 > 0 && poredjenje4 > 0)
                            {
                                continue;
                            }
                            else
                            {
                                carFromModels = null;
                                return(carFromModels);
                            }
                        }
                        else
                        {
                            carFromModels = null;
                            return(carFromModels);
                        }
                    }
                }
            }



            var pom1 = pom.FindAll(x => x.Mark.ToLower() == filterCar.Mark.ToLower());

            if (pom1.Count != 0)
            {
                var pom2 = pom1.FindAll(x => x.Seat == filterCar.Number.ToString());
                if (pom2.Count != 0)
                {
                    if (context.ReservationCar.ToList().Count == 0)
                    {
                        foreach (var cars in pom2)
                        {
                            CarFromModel cfm = new CarFromModel();
                            cfm.AirConditioning = cars.AirConditioning;
                            cfm.Bags            = Int32.Parse(cars.Bags);
                            cfm.Door            = Int32.Parse(cars.Door);
                            cfm.Fuel            = cars.Fuel;
                            cfm.Gearshift       = cars.Gearshift;
                            cfm.Id             = cars.Id;
                            cfm.ImageCar       = cars.ImageCar;
                            cfm.Mark           = cars.Mark;
                            cfm.RentPerDay     = Int32.Parse(cars.RentPerDay);
                            cfm.Seat           = Int32.Parse(cars.Seat);
                            cfm.YearProduction = Int32.Parse(cars.YearProduction);
                            cfm.Rating         = cars.AverageRating.ToString();
                            carFromModels.Add(cfm);
                        }
                    }

                    else
                    {
                        foreach (var cars in pom2)
                        {
                            var rez = rezervacije.FindAll(x => x.IdCar == cars.Id);
                            Model.ReservationCar rc = new Model.ReservationCar();

                            if (rez.Count() != 0)
                            {
                                foreach (var rezervacija in rez)
                                {
                                    int result  = DateTime.Compare(filterCar.startDay, rezervacija.Day1);
                                    int result2 = DateTime.Compare(filterCar.endDay, rezervacija.Day1);

                                    if (result < 0 && result2 < 0)
                                    {
                                        continue;
                                    }
                                    else if (result > 0 && result2 > 0)
                                    {
                                        int result3 = DateTime.Compare(filterCar.startDay, rezervacija.Day2);
                                        int result4 = DateTime.Compare(filterCar.endDay, rezervacija.Day2);


                                        if (result3 > 0 && result4 > 0)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            carFromModels = null;
                                            return(carFromModels);
                                        }
                                    }
                                    else
                                    {
                                        carFromModels = null;
                                        return(carFromModels);
                                    }
                                }

                                TimeSpan t = filterCar.endDay - filterCar.startDay;

                                var elapsedDays = t.Days;

                                var price = elapsedDays * Int32.Parse(cars.RentPerDay);

                                CarFromModel cfm = new CarFromModel();
                                cfm.AirConditioning = cars.AirConditioning;
                                cfm.Bags            = Int32.Parse(cars.Bags);
                                cfm.Door            = Int32.Parse(cars.Door);
                                cfm.Fuel            = cars.Fuel;
                                cfm.Gearshift       = cars.Gearshift;
                                cfm.Id             = cars.Id;
                                cfm.ImageCar       = cars.ImageCar;
                                cfm.Mark           = cars.Mark;
                                cfm.RentPerDay     = Int32.Parse(cars.RentPerDay);
                                cfm.Seat           = Int32.Parse(cars.Seat);
                                cfm.YearProduction = Int32.Parse(cars.YearProduction);
                                cfm.Price          = price.ToString();
                                cfm.Rating         = cars.AverageRating.ToString();
                                carFromModels.Add(cfm);
                            }

                            else
                            {
                                foreach (var car in pom2)
                                {
                                    CarFromModel cfm = new CarFromModel();
                                    cfm.AirConditioning = car.AirConditioning;
                                    cfm.Bags            = Int32.Parse(car.Bags);
                                    cfm.Door            = Int32.Parse(car.Door);
                                    cfm.Fuel            = car.Fuel;
                                    cfm.Gearshift       = car.Gearshift;
                                    cfm.Id             = car.Id;
                                    cfm.ImageCar       = car.ImageCar;
                                    cfm.Mark           = car.Mark;
                                    cfm.RentPerDay     = Int32.Parse(car.RentPerDay);
                                    cfm.Seat           = Int32.Parse(car.Seat);
                                    cfm.YearProduction = Int32.Parse(car.YearProduction);
                                    cfm.Rating         = cars.AverageRating.ToString();
                                    carFromModels.Add(cfm);
                                }
                                return(carFromModels);
                            }
                        }


                        return(carFromModels);
                    }
                }
                else
                {
                    return(carFromModels);
                }
            }
            else
            {
                return(carFromModels);
            }

            return(carFromModels);
        }
Beispiel #18
0
        public async Task <IActionResult> GetCompanyDetails(long id)
        {
            CarCompany company = await CarService.GetCompany(id);

            CarCompanyProfile companyProfile = new CarCompanyProfile();

            CarCompanyProfileDTO carCompanyProfileDTO = new CarCompanyProfileDTO();

            List <Office>  officeList    = company.Offices;
            List <Vehicle> vehicleList   = company.Vehicles;
            List <int>     vehicleRating = new List <int>();

            foreach (var vehicle in vehicleList)
            {
                vehicleRating.Add(await VehicleService.GetVehicleRatingAsInteger(vehicle.VehicleId));
            }

            int carCompanyRatingPicture = 0;

            if (ModelState.IsValid)
            {
                List <OfficeDTO> officeDTOList = new List <OfficeDTO>();

                for (int i = 0; i < officeList.Count; i++)
                {
                    OfficeDTO officeDTO = new OfficeDTO();

                    DestinationDTO destinationDTO = new DestinationDTO();

                    destinationDTO.Latitude  = officeList[i].Location.Latitude;
                    destinationDTO.Longitude = officeList[i].Location.Longitude;
                    destinationDTO.Name      = officeList[i].Location.Name;

                    officeDTO.OfficeId = officeList[i].OfficeId;
                    officeDTO.Location = destinationDTO;
                    officeDTO.Address  = officeList[i].Address;

                    officeDTOList.Add(officeDTO);
                }

                List <VehicleDTO> vehicleDTOList = new List <VehicleDTO>();

                for (int i = 0; i < vehicleList.Count; i++)
                {
                    VehicleDTO vehicleDTO = new VehicleDTO();

                    vehicleDTO.Additional   = vehicleList[i].Additional;
                    vehicleDTO.Baggage      = vehicleList[i].Baggage;
                    vehicleDTO.CarType      = vehicleList[i].CarType;
                    vehicleDTO.CostPerDay   = vehicleList[i].CostPerDay;
                    vehicleDTO.Doors        = vehicleList[i].Doors;
                    vehicleDTO.Fuel         = vehicleList[i].Fuel;
                    vehicleDTO.Name         = vehicleList[i].Name;
                    vehicleDTO.Passangers   = vehicleList[i].Passangers;
                    vehicleDTO.Rating       = vehicleRating[i];
                    vehicleDTO.Transmission = vehicleList[i].Transmission;
                    vehicleDTO.VehicleId    = vehicleList[i].VehicleId;
                    vehicleDTO.Additional   = vehicleList[i].Additional;

                    vehicleDTOList.Add(vehicleDTO);
                }

                string allOfficies = "";
                for (int i = 0; i < officeList.Count; i++)
                {
                    allOfficies += officeList[i].Location.Name + ",";
                }

                companyProfile = await CarService.GetCompanyProfile(id);

                carCompanyRatingPicture = await CarService.GetCompanyRatingAsInteger(id);

                carCompanyProfileDTO.Id            = company.CarCompanyId;
                carCompanyProfileDTO.Name          = companyProfile.Name;
                carCompanyProfileDTO.RatingPicture = carCompanyRatingPicture;
                carCompanyProfileDTO.Address       = companyProfile.Address;
                carCompanyProfileDTO.Description   = companyProfile.PromoDescription;
                carCompanyProfileDTO.OfficeList    = officeList;
                carCompanyProfileDTO.VehicleList   = vehicleDTOList;
                carCompanyProfileDTO.Offices       = allOfficies;

                return(Ok(new { carCompanyProfileDTO }));
            }
            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
Beispiel #19
0
 public async Task UpdateCompany(CarCompany company)
 {
     await _rentACarRepository.UpdateCompany(company);
 }
Beispiel #20
0
 public async Task UpdateCarCompany(CarCompany carCompany)
 {
     _context.Update(carCompany);
     await _context.SaveChangesAsync();
 }