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)); }
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.")); }
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)); }
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.")); }
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.")); }
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.")); }
public CarAdminController(RentACarService rentACarService, CarAdminService carAdminService, VehicleService vehicleService, OfficeService officeService) { RentACarService = rentACarService; CarAdminService = carAdminService; VehicleService = vehicleService; OfficeService = officeService; }
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)); }
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 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)); }
public async Task <IActionResult> RemoveCarAdmin(string id) { if (ModelState.IsValid) { var result = await CarAdminService.RemoveAdminById(id); if (result) { return(Ok(200)); } else { return(BadRequest("Admin wasn't found.")); } } return(BadRequest("No sufficient data provided.")); }
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)); }
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.")); }