Пример #1
0
        public async Task <IActionResult> UpdateCompanyProfile([FromBody] CarCompanyProfile model)
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var carCompanyProfile = await RentACarService.GetCompanyProfile(carCompany.CarCompanyProfileId);

                        carCompanyProfile.Name             = model.Name;
                        carCompanyProfile.Address          = model.Address;
                        carCompanyProfile.PromoDescription = model.PromoDescription;

                        await RentACarService.UpdateCompanyProfile(carCompanyProfile);

                        return(Ok(200));
                    }

                    return(BadRequest("Car company not found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

            return(BadRequest("Not enough data provided."));
        }
Пример #2
0
        public async Task <IActionResult> RemoveOffice(long id)
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var office = carCompany.Offices.Where(o => o.OfficeId == id).SingleOrDefault();

                        if (office != null)
                        {
                            await OfficeService.RemoveOffice(office);

                            return(Ok(200));
                        }

                        return(NotFound("Office wasn't found."));
                    }
                    else
                    {
                        return(BadRequest("Car company wasn't found."));
                    }
                }
            }

            return(BadRequest("No sufficient data provided."));
        }
Пример #3
0
        public async Task <IActionResult> GetCompanyProfile()
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var carCompanyProfile = await RentACarService.GetCompanyProfile(carCompany.CarCompanyProfileId);

                        return(Ok(new { carCompany, carCompanyProfile }));
                    }

                    return(BadRequest("Car company not found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
Пример #4
0
        public async Task <IActionResult> GetCompanyReport()
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var companyRating = await RentACarService.GetCompanyRatingAsInteger(carCompany.CarCompanyId);

                        var graph = await RentACarService.GetLastMonthsCarReservations(carCompany.CarCompanyId, 6);

                        return(Ok(new { companyRating, graph }));
                    }

                    return(BadRequest("Car company not found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
Пример #5
0
        public async Task <IActionResult> CreateOffice([FromBody] OfficeRequest model)
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var office = new Office()
                        {
                            Address  = model.Address,
                            Location = new Destination()
                            {
                                Name = model.City
                            },
                            CarCompanyId = carCompany.CarCompanyId
                        };

                        carCompany.Offices.Add(office);
                        await RentACarService.UpdateCompany(carCompany);

                        return(Ok(200));
                    }
                    return(BadRequest("Car company not found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

            return(BadRequest("Not enough data provided."));
        }
Пример #6
0
        public async Task <IActionResult> CreateCarAdmin([FromBody] RegisterAdminDTO adminDTO)
        {
            if (ModelState.IsValid)
            {
                if (await AvioAdminService.AdminExists(adminDTO.Username))
                {
                    return(BadRequest("Admin already exists with that username!"));
                }

                if (await CarAdminService.AdminExists(adminDTO.Username))
                {
                    return(BadRequest("Admin already exists with that username!"));
                }

                if (adminDTO.Password != adminDTO.ConfirmPassword)
                {
                    return(BadRequest("Password and confirmation password don't match!"));
                }

                RegularUser user = new RegularUser()
                {
                    UserName = adminDTO.Username,
                    Status   = UserStatus.Activated
                };

                var foundAdmin = await UserManager.FindByNameAsync(user.UserName) != null;

                if (!foundAdmin)
                {
                    var createdAdmin = await UserManager.CreateAsync(user, adminDTO.Password);

                    if (createdAdmin.Succeeded)
                    {
                        await UserManager.AddToRoleAsync(user, "CarAdmin");

                        CarAdmin admin = new CarAdmin()
                        {
                            UserId       = user.Id,
                            CarCompanyId = (await RentACarService.GetCompanyByName(adminDTO.CompanyName)).CarCompanyId
                        };

                        if (admin.CarCompanyId > 0)
                        {
                            await CarAdminService.RegisterAdmin(user.Id, admin);

                            return(Ok(200));
                        }
                        else
                        {
                            return(BadRequest("Car company not found!"));
                        }
                    }
                }

                return(BadRequest("Admin already exists!"));
            }

            return(BadRequest("No sufficient data provided."));
        }
Пример #7
0
 public CarAdminController(RentACarService rentACarService, CarAdminService carAdminService, VehicleService vehicleService,
                           OfficeService officeService)
 {
     RentACarService = rentACarService;
     CarAdminService = carAdminService;
     VehicleService  = vehicleService;
     OfficeService   = officeService;
 }
Пример #8
0
        public async Task <IActionResult> GetAdmins()
        {
            List <AdminDTO> retVal = new List <AdminDTO>();

            var avioAdmins = await AvioAdminService.GetAdmins();

            foreach (AvioAdmin admin in avioAdmins)
            {
                var user = await AvioAdminService.GetAdminUser(admin.UserId);

                if (admin.AvioCompanyId > 0)
                {
                    var company = await AvioService.GetCompany(admin.AvioCompanyId);

                    if (company != null)
                    {
                        var companyProfile = await AvioService.GetCompanyProfile(company.AvioCompanyProfileId);

                        retVal.Add(new AdminDTO()
                        {
                            Id        = user.Id,
                            Username  = user.UserName,
                            AdminType = "Avio Company Admin",
                            Company   = companyProfile.Name
                        });
                    }
                }
            }

            var carAdmins = await CarAdminService.GetAdmins();

            foreach (CarAdmin admin in carAdmins)
            {
                var user = await CarAdminService.GetAdminUser(admin.UserId);

                if (admin.CarCompanyId > 0)
                {
                    var company = await RentACarService.GetCompany(admin.CarCompanyId);

                    if (company != null)
                    {
                        var companyProfile = await RentACarService.GetCompanyProfile(company.CarCompanyProfileId);

                        retVal.Add(new AdminDTO()
                        {
                            Id        = user.Id,
                            Username  = user.UserName,
                            AdminType = "Car Company Admin",
                            Company   = companyProfile.Name
                        });
                    }
                }
            }

            return(Ok(retVal));
        }
Пример #9
0
 public SystemController(UserManager <RegularUser> userManager, UserService userService, AvioService avioService, RentACarService rentACarService,
                         AvioAdminService avioAdminService, CarAdminService carAdminService)
 {
     UserManager      = userManager;
     UserService      = userService;
     AvioService      = avioService;
     RentACarService  = rentACarService;
     AvioAdminService = avioAdminService;
     CarAdminService  = carAdminService;
 }
 public UserController(UserService userService, FlightService flightService, ReservationService reservationService,
                       AvioService avioService, VehicleService vehicleService, RentACarService rentACarService, IConfiguration configuration)
 {
     _userService        = userService;
     _configuration      = configuration;
     _flightService      = flightService;
     _reservationService = reservationService;
     _avioService        = avioService;
     _vehicleService     = vehicleService;
     _rentACarService    = rentACarService;
 }
Пример #11
0
        public async Task <IActionResult> GetCompanyVehicles()
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var vehicles = carCompany.Vehicles;

                        List <VehicleDTO> vehicleDTOs = new List <VehicleDTO>();
                        foreach (Vehicle v in vehicles)
                        {
                            vehicleDTOs.Add(new VehicleDTO()
                            {
                                VehicleId    = v.VehicleId,
                                Additional   = v.Additional,
                                Baggage      = v.Baggage,
                                CarType      = v.CarType,
                                CostPerDay   = v.CostPerDay,
                                Doors        = v.Doors,
                                Fuel         = v.Fuel,
                                Name         = v.Name,
                                Passangers   = v.Passangers,
                                Transmission = v.Transmission,
                                Rating       = await VehicleService.GetVehicleRatingAsInteger(v.VehicleId)
                            });
                        }

                        return(Ok(vehicleDTOs));
                    }

                    return(BadRequest("Car company not found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
Пример #12
0
        public async Task <IActionResult> RemoveCarCompany(long id)
        {
            if (ModelState.IsValid)
            {
                var result = await RentACarService.RemoveCompany(id);

                if (result)
                {
                    return(Ok(200));
                }
                else
                {
                    return(BadRequest("Company wasn't found."));
                }
            }

            return(BadRequest("No sufficient data provided."));
        }
Пример #13
0
        public async Task <IActionResult> GetCompanyOffices()
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var offices = carCompany.Offices;

                        List <OfficeDTO> officeDTOs = new List <OfficeDTO>();
                        foreach (Office o in offices)
                        {
                            officeDTOs.Add(new OfficeDTO()
                            {
                                Location = new DestinationDTO()
                                {
                                    Name      = o.Location.Name,
                                    Latitude  = o.Location.Latitude,
                                    Longitude = o.Location.Longitude
                                },
                                Address  = o.Address,
                                OfficeId = o.OfficeId
                            });
                        }

                        return(Ok(officeDTOs));
                    }
                    return(BadRequest("Car company not found."));
                }

                return(Unauthorized("You must log in as an administrator of this company."));
            }

            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
Пример #14
0
        public async Task <IActionResult> GetCarCompanies()
        {
            var carCompanies = await RentACarService.GetCompanies();

            List <CarCompanyDTO> retVal = new List <CarCompanyDTO>();

            foreach (CarCompany carCompany in carCompanies)
            {
                var carCompanyProfile = await RentACarService.GetCompanyProfile(carCompany.CarCompanyProfileId);

                retVal.Add(new CarCompanyDTO()
                {
                    Id          = carCompany.CarCompanyId,
                    Name        = carCompanyProfile.Name,
                    Address     = carCompanyProfile.Address,
                    Description = carCompanyProfile.PromoDescription
                });
            }

            return(Ok(retVal));
        }
Пример #15
0
        public async Task <IActionResult> CreateCarCompany([FromBody] CarCompanyDTO carCompanyDTO)
        {
            if (ModelState.IsValid)
            {
                if (await RentACarService.CompanyExists(carCompanyDTO.Name))
                {
                    return(BadRequest("Company already exists."));
                }

                var profile = new CarCompanyProfile()
                {
                    Name             = carCompanyDTO.Name,
                    Address          = carCompanyDTO.Address,
                    PromoDescription = carCompanyDTO.Description
                };

                await RentACarService.CreateCompany(profile);

                return(Ok(200));
            }

            return(BadRequest("No sufficient data provided."));
        }
Пример #16
0
        public async Task <IActionResult> CreateVehicle([FromBody] VehicleDTO model)
        {
            if (ModelState.IsValid)
            {
                var user = await CarAdminService.GetCurrentUser();

                if (user != null)
                {
                    var carCompany = await RentACarService.GetCompany(user.CarCompanyId);

                    if (carCompany != null)
                    {
                        var vehicle = new Vehicle()
                        {
                            Additional   = model.Additional,
                            Baggage      = model.Baggage,
                            CarCompanyId = carCompany.CarCompanyId,
                            CarType      = model.CarType,
                            CostPerDay   = model.CostPerDay,
                            Doors        = model.Doors,
                            Fuel         = model.Fuel,
                            Name         = model.Name,
                            Passangers   = model.Passangers,
                            Transmission = model.Transmission
                        };

                        carCompany.Vehicles.Add(vehicle);
                        await RentACarService.UpdateCompany(carCompany);

                        return(Ok(200));
                    }
                }
            }

            return(BadRequest("Not enough data provided."));
        }
Пример #17
0
 public CarController(RentACarService carService, DestinationService destinationService, VehicleService vehicleService)
 {
     CarService         = carService;
     DestinationService = destinationService;
     VehicleService     = vehicleService;
 }
        public async Task <Object> AddRACService(RentACarModel model)
        {
            //int id = Int32.Parse(model.idAdmin);

            User tmpUser = await _context.Users
                           .Include(address => address.address)
                           //.Include(friends => friends.friends)
                           //.Include(friendRequests => friendRequests.friendRequests)
                           .FirstOrDefaultAsync(i => i.Id == model.idAdmin);

            if (tmpUser == null)
            {
                return(BadRequest("Ne postoji korisnik!"));
            }

            RentACarService rac = new RentACarService();
            Address         adr = new Address();
            Cenovnik        cen = new Cenovnik();

            cen.StavkeCenovnika = new List <StavkaCenovnika>();
            StavkaCenovnika stavka1 = new StavkaCenovnika();
            StavkaCenovnika stavka2 = new StavkaCenovnika();
            StavkaCenovnika stavka3 = new StavkaCenovnika();
            StavkaCenovnika stavka4 = new StavkaCenovnika();
            StavkaCenovnika stavka5 = new StavkaCenovnika();

            rac.Name        = model.Name;
            rac.Description = model.Description;
            rac.LogoImage   = model.LogoImage;

            adr.city            = model.city;
            adr.country         = model.country;
            adr.streetAndNumber = model.streetAndNumber;
            adr.deleted         = false;

            rac.RACAddress = adr;

            stavka1.Naziv    = "BabySeat";
            stavka1.Vrednost = Int32.Parse(model.BabySeat);
            stavka1.deleted  = false;
            cen.StavkeCenovnika.Add(stavka1);
            stavka2.Naziv    = "Navigation";
            stavka2.Vrednost = Int32.Parse(model.Navigation);
            stavka2.deleted  = false;
            cen.StavkeCenovnika.Add(stavka2);
            stavka3.Naziv    = "Roof";
            stavka3.Vrednost = Int32.Parse(model.Roof);
            stavka3.deleted  = false;
            cen.StavkeCenovnika.Add(stavka3);
            stavka4.Naziv    = "Luxuary";
            stavka4.Vrednost = Int32.Parse(model.Luxuary);
            stavka4.deleted  = false;
            cen.StavkeCenovnika.Add(stavka4);
            stavka5.Naziv    = "Discount";
            stavka5.Vrednost = Int32.Parse(model.Discount);
            stavka5.deleted  = false;
            cen.StavkeCenovnika.Add(stavka5);
            cen.deleted = false;

            rac.Cenovnik = cen;

            rac.RACidAdmin = tmpUser.Id;

            Grad pom = await _context.Gradovi
                       .FirstOrDefaultAsync(i => i.city == adr.city);

            if (pom == null)
            {
                Grad grad = new Grad();
                grad.city        = adr.city;
                grad.description = "Promotivni opis. . .";
                grad.images      = model.LogoImage;

                _context.Gradovi.Add(grad);
            }

            _context.RentACarServices.Add(rac);

            try
            {
                await _context.SaveChangesAsync();
            }
#pragma warning disable CS0168 // The variable 'e' is declared but never used
            catch (Exception e)
#pragma warning restore CS0168 // The variable 'e' is declared but never used
            {
                throw;
            }
            return(rac);
        }
Пример #19
0
        public async Task <IActionResult> RegisterRACSAdmin([FromBody] RegisterRACSAdminDto registerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Model is invalid."));
            }

            try
            {
                string userId   = User.Claims.First(c => c.Type == "UserID").Value;
                string userRole = User.Claims.First(c => c.Type == "Roles").Value;
                var    user     = await unitOfWork.UserManager.FindByIdAsync(userId);

                if (!userRole.Equals("Admin"))
                {
                    return(Unauthorized());
                }

                if (user == null)
                {
                    return(NotFound("User not found"));
                }

                //if ((await unitOfWork.AuthenticationRepository.GetPersonByEmail(registerDto.Email)) != null)
                //{
                //    return BadRequest("User with that email already exists!");
                //}
                if ((await unitOfWork.AuthenticationRepository.GetPersonByUserName(registerDto.UserName)) != null)
                {
                    return(BadRequest("User with that usermane already exists!"));
                }
                if (registerDto.Password.Length > 20 || registerDto.Password.Length < 8)
                {
                    return(BadRequest("Password length has to be between 8-20"));
                }
                if (!unitOfWork.AuthenticationRepository.CheckPasswordMatch(registerDto.Password, registerDto.ConfirmPassword))
                {
                    return(BadRequest("Passwords dont match"));
                }
                var admin = new RentACarServiceAdmin()
                {
                    Email    = registerDto.Email,
                    UserName = registerDto.UserName,
                };
                var racs = new RentACarService()
                {
                    Name    = registerDto.Name,
                    Address = new Address2()
                    {
                        City  = registerDto.Address.City,
                        State = registerDto.Address.State,
                        Lat   = registerDto.Address.Lat,
                        Lon   = registerDto.Address.Lon,
                    },
                    Admin = (RentACarServiceAdmin)admin
                };

                admin.RentACarService = racs;
                //using (var transaction = new TransactionScope())
                //{

                try
                {
                    await this.unitOfWork.AuthenticationRepository.RegisterRACSAdmin(admin, registerDto.Password);

                    await unitOfWork.AuthenticationRepository.AddToRole(admin, "RentACarServiceAdmin");

                    await unitOfWork.Commit();

                    //await transaction.Result.CommitAsync();
                }
                catch (Exception)
                {
                    //await transaction.Result.RollbackAsync();
                    //unitOfWork.Rollback();
                    return(StatusCode(500, "Failed to register racs admin. One of transactions failed"));
                }
                //}

                try
                {
                    var emailSent = await unitOfWork.AuthenticationRepository.SendConfirmationMail(admin, "admin", registerDto.Password);
                }
                catch (Exception)
                {
                    return(StatusCode(500, "Failed to send registration email"));
                }

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode(500, "Failed to register racs admin"));
            }
        }