public IActionResult Create(string reference, string path, string name) { if (ModelState.IsValid) { gitCloneServices.GitClone(reference, path); gitInitService.GitInit(path); var repos = new Repos { Name = name, Path = path }; _context.Add(repos); _context.SaveChanges(); var analysis = new Analysis { Date = DateTime.Now, Repos = _context.Repos.SingleOrDefault(x => x.Id == repos.Id) }; _context.Add(analysis); _context.SaveChanges(); int RepoId = repos.Id; string Path = path; int AnalysisId = analysis.Id; counterChange.CounterChangeFileInLocalrepositiry(RepoId, Path, AnalysisId); } return(View("Index")); }
static void Main(string[] args) { Console.WriteLine("Creating Default Db Context"); //To connect to an sql or azure sql server jusr use: UseSqlServer(connectionString) var options = new DbContextOptionsBuilder <RepositoryDbContext>() .UseSqlite("Data Source=endavaUniversity.db") //.UseLoggerFactory(loggerFactory) .Options; using (var db = new RepositoryDbContext(options)) { // Create var user = new User { FirstName = "Maria", LastName = "Antuanetta" }; Console.WriteLine($"Inserting a new user: {user.FirstName} {user.LastName}."); db.Add(user); db.SaveChanges(); // Read Console.WriteLine("Querying for a user"); var returnedUser = db.Users .OrderBy(u => u.Id) .Where(u => u.FirstName.Equals(user.FirstName)).First(); Console.WriteLine($"User: {returnedUser.FirstName} {returnedUser.LastName}; Id: {returnedUser.Id}"); // Update Console.WriteLine("Updating the user (Carlos) and adding a wallet"); returnedUser.LastName = "Carlos"; returnedUser.Wallets.Add( new Wallet { Amount = 100, Currency = "USD", }); db.SaveChanges(); // Read Console.WriteLine("Querying for an updated user"); var updatedUser = db.Users .OrderBy(u => u.Id) .Where(u => u.FirstName.Equals(user.FirstName)).First(); Console.WriteLine($"User: {updatedUser.FirstName} {updatedUser.LastName}; Id: {updatedUser.Id}"); Console.WriteLine($"User' wallet Id: {updatedUser.Wallets.First()?.Id}"); Console.WriteLine($"Wallet' user Id: {updatedUser.Wallets.First()?.UserId}"); // Delete Console.WriteLine("Delete the user"); db.Remove(updatedUser); db.SaveChanges(); } }
public async Task <IActionResult> Create([Bind("Id,Name,Path")] Repos repos) { if (ModelState.IsValid) { _context.Add(repos); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(repos)); }
public async Task <IActionResult> Create([Bind("Id, RepoId, Path")] AnalisisViewModel analisisViewModel) { if (ModelState.IsValid) { var analysis = new Analysis { Date = DateTime.Now, Repos = _context.Repos.SingleOrDefault(x => x.Id == analisisViewModel.Id) }; _context.Add(analysis); await _context.SaveChangesAsync(); int RepoId = analisisViewModel.RepoId; string Path = analisisViewModel.Path; int AnalysisId = analysis.Id; await counterChange.CounterChangeFileInLocalrepositiry(RepoId, Path, AnalysisId); return(RedirectToAction("Index", "Repos")); } return(View("Create")); }