diff --git a/.gitignore b/.gitignore index 9830e8d..31d1a0c 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ Back/skydiveLogs-api.Domain/bin/Release/net5.0/ref/skydiveLogs-api.Domain.dll Back/skydiveLogs-api.Domain/bin/Release/net5.0/skydiveLogs-api.Domain.dll Back/skydiveLogs-api.Domain/bin/Release/net5.0/skydiveLogs-api.Domain.pdb +Back/skydiveLogs-api/Data/JumpsDb-log.db +Back/skydiveLogs-api/Data/JumpsDb.db diff --git a/Back/skydiveLogs-api.DomainBusiness/GearService.cs b/Back/skydiveLogs-api.DomainBusiness/GearService.cs index 9cde48a..279af7d 100644 --- a/Back/skydiveLogs-api.DomainBusiness/GearService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/GearService.cs @@ -22,6 +22,23 @@ namespace skydiveLogs_api.DomainBusiness _gearRepository.Add(newGear); } + public void AddRentalGear(User connectedUser) + { + var rentalGear = new Gear + { + Name = "Rental gear", + Manufacturer = "?", + MainCanopy = "?", + Aad = "Cypress/Vigil", + MaxSize = 280, + MinSize = 190, + ReserveCanopy = "?", + User = connectedUser + }; + + _gearRepository.Add(rentalGear); + } + public void DeleteGearById(int id) { throw new NotImplementedException(); diff --git a/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs b/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs index b863a83..d17830d 100644 --- a/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs @@ -82,12 +82,12 @@ namespace skydiveLogs_api.DomainBusiness var adminUser = new User { Login = "administrator", - Password = "logsadmin" + Password = "logsadmin", + Email = "no mail" }; - _userService.AddNewUser(adminUser); + _userService.AddNewUser(adminUser, true); } - private readonly IAircraftService _aircraftService; private readonly IJumpTypeService _jumpTypeService; diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IGearService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IGearService.cs index 73276be..ca3ed49 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IGearService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IGearService.cs @@ -16,5 +16,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces void UpdateGear(int id, Gear gear); void AddNewGear(Gear gear, User connectedUser); + + void AddRentalGear(User connectedUser); } } diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs index a513320..46edd5d 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs @@ -8,6 +8,6 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces User GetById(int userId); - bool AddNewUser(User user); + bool AddNewUser(User user, bool isAdmin = false); } } diff --git a/Back/skydiveLogs-api.DomainBusiness/UserService.cs b/Back/skydiveLogs-api.DomainBusiness/UserService.cs index 0f01bca..56a038b 100644 --- a/Back/skydiveLogs-api.DomainBusiness/UserService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/UserService.cs @@ -12,9 +12,11 @@ namespace skydiveLogs_api.DomainBusiness { public class UserService : IUserService { - public UserService(IUserRepository userRepository) + public UserService(IUserRepository userRepository, + IGearService gearService) { _userRepository = userRepository; + _gearService = gearService; } public User GetById(int userId) @@ -27,7 +29,7 @@ namespace skydiveLogs_api.DomainBusiness return _userRepository.GetByLogin(login, EncryptPassword(password)); } - public bool AddNewUser(User newUser) + public bool AddNewUser(User newUser, bool isAdmin = false) { newUser.Password = EncryptPassword(newUser.Password); var foundUser = _userRepository.GetByLogin(newUser.Login, newUser.Password); @@ -35,8 +37,15 @@ namespace skydiveLogs_api.DomainBusiness if (foundUser == null) { - newUser.IsAdmin = false; - result = _userRepository.Add(newUser); + newUser.IsAdmin = isAdmin; + var newUserId = _userRepository.Add(newUser); + result = (newUserId > 0); + + if (result) + { + newUser.Id = newUserId; + _gearService.AddRentalGear(newUser); + } } return result; @@ -70,5 +79,7 @@ namespace skydiveLogs_api.DomainBusiness } private readonly IUserRepository _userRepository; + + private readonly IGearService _gearService; } } diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs index 2e6ab11..15d47af 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs @@ -10,6 +10,6 @@ namespace skydiveLogs_api.DomainService.Repositories bool Update(T updated); - bool Add(T newEntity); + int Add(T newEntity); } } \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs b/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs index 52c9d27..2d51ebe 100644 --- a/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs @@ -33,17 +33,18 @@ namespace skydiveLogs_api.Infrastructure return _col.Update(aircraft); } - public bool Add(Aircraft newAircraft) + public int Add(Aircraft newAircraft) { - var result = true; + int result; try { - _col.Insert(newAircraft); + var tmp = _col.Insert(newAircraft); + result = tmp.AsInt32; } catch { - result = false; + result = 0; } return result; diff --git a/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs b/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs index 8cec9f8..043354b 100644 --- a/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs @@ -33,17 +33,18 @@ namespace skydiveLogs_api.Infrastructure return _col.Update(updatedDz); } - public bool Add(DropZone newDz) + public int Add(DropZone newDz) { - var result = true; + int result; try { - _col.Insert(newDz); + var tmp = _col.Insert(newDz); + result = tmp.AsInt32; } catch { - result = false; + result = 0; } return result; diff --git a/Back/skydiveLogs-api.Infrastructure/GearRepository.cs b/Back/skydiveLogs-api.Infrastructure/GearRepository.cs index f3ae4b8..ec8df9b 100644 --- a/Back/skydiveLogs-api.Infrastructure/GearRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/GearRepository.cs @@ -40,17 +40,18 @@ namespace skydiveLogs_api.Infrastructure return _col.Update(updatedGear); } - public bool Add(Gear newGear) + public int Add(Gear newGear) { - var result = true; + int result; try { - _col.Insert(newGear); + var tmp = _col.Insert(newGear); + result = tmp.AsInt32; } catch { - result = false; + result = 0; } return result; diff --git a/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs b/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs index a56a5f7..6804153 100644 --- a/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs @@ -34,17 +34,18 @@ namespace skydiveLogs_api.Infrastructure return _col.FindById(new BsonValue(id)); } - public bool Add(Jump newJump) + public int Add(Jump newJump) { - var result = true; + int result; try { - _col.Insert(newJump); + var tmp = _col.Insert(newJump); + result = tmp.AsInt32; } catch { - result = false; + result = 0; } return result; diff --git a/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs b/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs index ee5adbb..495cd53 100644 --- a/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs @@ -33,17 +33,18 @@ namespace skydiveLogs_api.Infrastructure return _col.Update(updatedJumpType); } - public bool Add(JumpType newJumpType) + public int Add(JumpType newJumpType) { - var result = true; + int result; try { - _col.Insert(newJumpType); + var tmp = _col.Insert(newJumpType); + result = tmp.AsInt32; } catch { - result = false; + result = 0; } return result; diff --git a/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs index 375d089..c9fa66d 100644 --- a/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs @@ -40,17 +40,18 @@ namespace skydiveLogs_api.Infrastructure return _col.Update(image); } - public bool Add(UserImage newImage) + public int Add(UserImage newImage) { - var result = true; + int result; try { - _col.Insert(newImage); + var tmp = _col.Insert(newImage); + result = tmp.AsInt32; } catch { - result = false; + result = 0; } return result; diff --git a/Back/skydiveLogs-api.Infrastructure/UserRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserRepository.cs index 883bf5d..56867cd 100644 --- a/Back/skydiveLogs-api.Infrastructure/UserRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/UserRepository.cs @@ -23,17 +23,18 @@ namespace skydiveLogs_api.Infrastructure return _col.FindOne(u => u.Login == login && u.Password == password); } - public bool Add(User newUser) + public int Add(User newUser) { - var result = true; + int result; try { - _col.Insert(newUser); + var tmp = _col.Insert(newUser); + result = tmp.AsInt32; } catch { - result = false; + result = 0; } return result; diff --git a/Back/skydiveLogs-api/Data/LiteDB.Studio-v1.0.1.exe b/Back/skydiveLogs-api/Data/LiteDB.Studio-v1.0.1.exe deleted file mode 100644 index ffa5a85..0000000 Binary files a/Back/skydiveLogs-api/Data/LiteDB.Studio-v1.0.1.exe and /dev/null differ diff --git a/Back/skydiveLogs-api/skydiveLogs-api.csproj.user b/Back/skydiveLogs-api/skydiveLogs-api.csproj.user index 6398148..3997150 100644 --- a/Back/skydiveLogs-api/skydiveLogs-api.csproj.user +++ b/Back/skydiveLogs-api/skydiveLogs-api.csproj.user @@ -11,5 +11,9 @@ False C:\Projects\SkydiveLogs\Back\skydiveLogs-api\Properties\PublishProfiles\FolderProfile.pubxml false + skydiveLogs_api + + + ProjectDebugger \ No newline at end of file