//Projects the user information contained into uploadDTO over a new User object public User UserDotUploadDTO(UploadDTO uploadDTO) { User newUser = GenerateNewUserFromDTO(uploadDTO); if (GenerateControlIfDuplicateUserOnDB(newUser) == null) { newUser = _userRepository.AddEntityReturned(newUser); _playStoreDBContext.SaveChanges(); } return(GenerateControlIfDuplicateUserOnDB(newUser)); }
public void AddUpload(UploadDTO uploadDTO) { //check sul valore nullo ArgumentNullException //*************************************************** var tempUser = new User() { Name = uploadDTO.DeveloperName, Surname = uploadDTO.DeveloperSurname, Email = uploadDTO.Email }; User checkUser = _playStoreDBContext.Users.Where(x => x.Email == tempUser.Email).FirstOrDefault(); if (checkUser == null) { //Add to Users User tempTempUser = _userRepository.AddEntityReturned(tempUser); //tempUser = tempTempUser; _playStoreDBContext.SaveChanges(); } tempUser = _playStoreDBContext.Users.Where(x => x.Email == tempUser.Email).FirstOrDefault(); //***************************************************** var tempApp = new App() { Name = uploadDTO.AppName, Genre = uploadDTO.Genre, LastUpdate = uploadDTO.LastUpdate, AppBrand = uploadDTO.AppBrand }; App checkApp = _playStoreDBContext.Apps.Where(x => x.LastUpdate == tempApp.LastUpdate).FirstOrDefault(); if (checkApp == null) { //Add to Apps App tempTempApp = _appRepository.AddEntityReturned(tempApp); //tempApp = tempTempApp; _playStoreDBContext.SaveChanges(); } tempApp = _playStoreDBContext.Apps.Where(x => x.LastUpdate == tempApp.LastUpdate).FirstOrDefault(); //***************************************************** var tempCompatibility = new Compatibilities() { DeviceType = uploadDTO.DeviceType }; //Add to Compatibilities Compatibilities tempTempCompatibility = _compatibilityRepository.AddEntityReturned(tempCompatibility); tempCompatibility = tempTempCompatibility; _playStoreDBContext.SaveChanges(); //***************************************************** var tempPrice = new Prices() { Currency = uploadDTO.Currency, Value = uploadDTO.Value }; //Add to Prices Prices tempTempPrice = _priceRepository.AddEntityReturned(tempPrice); tempPrice = tempTempPrice; _playStoreDBContext.SaveChanges(); //***************************************************** var tempUserApp = new UserApp() { UsersId = tempUser.Id, AppsId = tempApp.Id }; UserApp checkUserApp = _playStoreDBContext.UserApp.Where(x => x.UsersId == tempUserApp.UsersId && x.AppsId == tempUserApp.AppsId).FirstOrDefault(); if (checkUserApp == null) { //Add to UserApp UserApp tempTempUserApp = _userAppRepository.AddEntityReturned(tempUserApp); //tempUserApp=tempTempUserApp; _playStoreDBContext.SaveChanges(); } tempUserApp = _playStoreDBContext.UserApp.Where(x => x.UsersId == tempUserApp.UsersId && x.AppsId == tempUserApp.AppsId).FirstOrDefault(); //***************************************************** var tempUploads = new Uploads() { UsersId = tempUser.Id, UserAppId = tempUserApp.Id, Accepted = uploadDTO.Accepted, Update = uploadDTO.Update }; //Add to Uploads Uploads tempTempUploads = _uploadRepository.AddEntityReturned( tempUploads ); tempUploads = tempTempUploads; _playStoreDBContext.SaveChanges(); //***************************************************** }
public void SaveRepository() { _appStoreDBContext.SaveChanges(); }
static void Main(string[] args) { try { PlayStoreDBContext playStoreDBContext = new PlayStoreDBContext(); GenericRepository <User> usersRepository = new GenericRepository <User>(playStoreDBContext); GenericRepository <UserApp> userAppUploadRepository = new GenericRepository <UserApp>(playStoreDBContext); GenericRepository <App> appsRepository = new GenericRepository <App>(playStoreDBContext); PlayStore.DTO.AppDTO appDTO = new PlayStore.DTO.AppDTO(); AppService appService = new AppService(playStoreDBContext); // appsRepository.AddEntity(new Users() { // Name="Daniele", // Surname="Sicoli", // City="Genova", // Email = "*****@*****.**" // }); // appsRepository.AddEntity( // new Apps(){ // Name = "Fallout", // Genre = "Science fiction", // LastUpdate = "March", // AppBrand = "MyBrand" // } // ); // userAppUploadRepository.AddEntity( // new UserAppUpload(){ // }); // foreach(Users user in appStoreDBContext.Users) // { // Console.WriteLine(user.Name+" "+user.City+" "+user.Email); // } // usersRepository.Update(new Users(){ Name="Daniele", // Surname="Sicoli", // City="Genova", // Email = "*****@*****.**"}); // foreach(UserAppUpload row in appStoreDBContext.UserAppUpload) // { // Console.WriteLine(row.AppsId+" "+row.UsersId+" "+row.IsUpload); // } // appsRepository.DeleteSingleEntity(new Apps() { Id = 1 }); // appsRepository.Delete(e => e.Id % 2==0); appService.AddUpload(new UploadDTO() { DeveloperName = "Antonio", DeveloperSurname = "LR", Accepted = true, DeviceType = "Android", AppBrand = "Comitiva", AppName = "Mordi e fuggi", Currency = "$", Value = "10", Email = "*****@*****.**", LastUpdate = "20//06//2017" }); playStoreDBContext.SaveChanges(); List <App> returnedApps = new List <App>(appsRepository.GetAll()); foreach (App app in returnedApps) { Console.WriteLine("Name: " + app.Name + " " + "Brand: " + app.AppBrand); } } catch (Exception e) { Console.WriteLine("Message: " + e.Message); Console.WriteLine("Data; " + e.Data); Console.WriteLine("Source: " + e.Source); Console.WriteLine("Inner exception: " + e.InnerException); } }