public IActionResult Post(Aluno aluno) { context.Add(aluno); context.SaveChanges(); return(Ok(aluno)); }
public IActionResult Post(Aluno aluno) { //return Ok("Alunos: Denis, Vera, Isabella, Denis Filho"); _context.Add(aluno); _context.SaveChanges(); return(Ok(aluno)); }
public IActionResult Post(Professor Professor) { //return Ok("Professors: Denis, Vera, Isabella, Denis Filho"); _context.Add(Professor); _context.SaveChanges(); return(Ok(Professor)); }
public async Task <IActionResult> Add() { Categoria categoria = new Categoria() { Nome = "Artesenato", Descricao = "Para se fazer em casa" }; _context.Add(categoria); await _context.SaveChangesAsync(); return(View(await _context.Categoria.ToListAsync())); }
public IActionResult Post(Professor professor) { _context.Add(professor); _context.SaveChanges(); return(Ok()); }
public void Add <T>(T entity) where T : class { _context.Add(entity); }
public void TestAutoSwitchSmartContext_SwitchOnInsert_ObjectShouldBeInsertedInTheBackup() { using (SmartContext sCtx = new SmartContext()) { int usersInOfflineBefore = this.offlineContext.Users.Count(); User newUser = new User() { UserId = 7777, Name = "Ivan", Email = "*****@*****.**", Note = "note note note", Income = 15543m }; //Simulate that the online storage is not available this.LockDbTable("Users"); sCtx.Add(newUser); //Upon saving the changes, the SmartContext will switch to the backup storage and //persist the new user object there sCtx.SaveChanges(); int usersInOfflineAfter = this.offlineContext.Users.Count(); User newUserFromFromBackup = sCtx.GetSingle<User>(usr => usr.UserId == newUser.UserId); this.ReleaseLock(); User newUserFromOnline = this.onlineContext.Users.FirstOrDefault(usr => usr.UserId == newUser.UserId); Assert.IsNotNull(newUserFromFromBackup); Assert.IsNull(newUserFromOnline); Assert.AreNotEqual(usersInOfflineBefore, usersInOfflineAfter); Assert.AreEqual(usersInOfflineBefore + 1, usersInOfflineAfter); } }
public void TestSmartContext_InsertEntity_EntityShouldBeBackedUp() { using (SmartContext sCtx = new SmartContext()) { int usersInOfflineCountBefore = this.offlineContext.Users.Count(); User newUser = new User() { UserId = 1337, Name = "Mark", Email= "*****@*****.**", Note = "note note note", Income = 15543m }; sCtx.Add(newUser); sCtx.SaveChanges(); int usersInOfflineCountAfter = this.offlineContext.Users.Count(); User userFromOfflineStorage = this.offlineContext.Users.FirstOrDefault(usr => usr.UserId == newUser.UserId); Assert.IsNotNull(userFromOfflineStorage); Assert.AreEqual(usersInOfflineCountBefore + 1, usersInOfflineCountAfter); } }
public void TestSmartCotnext_InsertGroupWithNewRealtedUsers_AllShouldBeBackedUp() { using (SmartContext sCtx = new SmartContext()) { int usersInOfflineCountBefore = this.offlineContext.Users.Count(); int groupsInOfflineCountBefore = this.offlineContext.Groups.Count(); Group newGroup = new Group() { GroupId = 8888, Name = "NewGroup", Description = "New Group For Users" }; User newUser = new User() { UserId = 1337, Name = "Mark", Email = "*****@*****.**", Note = "note note note", Income = 15543m }; newGroup.UsersInGroup.Add(newUser); sCtx.Add(newGroup); sCtx.SaveChanges(); int usersInOfflineCountAfter = this.offlineContext.Users.Count(); int groupsInOfflineCountAfter = this.offlineContext.Groups.Count(); IEnumerable<User> usersFromOfflineStorage = this.offlineContext.Users.Where(usr => usr.UserId == newUser.UserId).ToList(); IEnumerable<Group> groupsFromOfflineStorage = this.offlineContext.Groups.Where(grp => grp.GroupId == newGroup.GroupId).ToList(); Assert.AreNotEqual(usersInOfflineCountBefore, usersInOfflineCountAfter); Assert.AreNotEqual(groupsInOfflineCountBefore, groupsInOfflineCountAfter); Assert.AreEqual(1, usersFromOfflineStorage.Count()); Assert.AreEqual(1, groupsFromOfflineStorage.Count()); } }
public void TestSmartCotnext_InsertGroupWithExistingRealtedUsers_AllShouldBeBackedUp() { using (SmartContext sCtx = new SmartContext()) { int usersInOfflineCountBefore = this.offlineContext.Users.Count(); int groupsInOfflineCountBefore = this.offlineContext.Groups.Count(); Group newGroup = new Group() { GroupId = 8888, Name = "NewGroup", Description = "New Group For Users" }; sCtx.Add(newGroup); sCtx.SaveChanges(); User existingUser = sCtx.GetSingle<User>(); newGroup.UsersInGroup.Add(existingUser); sCtx.SaveChanges(); int usersInOfflineCountAfter = this.offlineContext.Users.Count(); int groupsInOfflineCountAfter = this.offlineContext.Groups.Count(); IEnumerable<User> usersFromOfflineStorage = this.offlineContext.Users.Where(usr => usr.UserId == existingUser.UserId).ToList(); IEnumerable<Group> groupsFromOfflineStorage = this.offlineContext.Groups.Where(grp => grp.GroupId == newGroup.GroupId).ToList(); Assert.AreNotEqual(usersInOfflineCountBefore, usersInOfflineCountAfter); Assert.AreNotEqual(groupsInOfflineCountBefore, groupsInOfflineCountAfter); Assert.AreEqual(1, usersFromOfflineStorage.Count()); Assert.AreEqual(1, groupsFromOfflineStorage.Count()); } }
public void TestSmartContext_InsertUsersWithNewRelatedGroup_AllShouldBeBackedUp() { using (SmartContext sCtx = new SmartContext()) { int usersInOfflineCountBefore = this.offlineContext.Users.Count(); int groupsInOfflineCountBefore = this.offlineContext.Groups.Count(); Group newGroup = new Group() { GroupId = 1227, Name = "New Group", Description = "Group of newness" }; User newUser1 = new User() { UserId = 1337, Name = "Mark", Email = "*****@*****.**", Note = "note note note", Income = 15543m }; newUser1.Group = newGroup; User newUser2 = new User() { UserId = 1338, Name = "Harry", Email = "*****@*****.**", Note = "note note note", Income = 12543m }; newUser2.Group = newGroup; sCtx.Add(newUser1); sCtx.Add(newUser2); sCtx.SaveChanges(); int usersInOfflineCountAfter = this.offlineContext.Users.Count(); int groupsInOfflineCountAfter = this.offlineContext.Groups.Count(); IEnumerable<User> usersFromOfflineStorage = this.offlineContext.Users.Where(usr => usr.UserId == newUser1.UserId || usr.UserId == newUser2.UserId).ToList(); IEnumerable<Group> groupsFromOfflineStorage = this.offlineContext.Groups.Where(grp => grp.GroupId == newGroup.GroupId).ToList(); Assert.AreNotEqual(usersInOfflineCountBefore, usersInOfflineCountAfter); Assert.AreNotEqual(groupsInOfflineCountBefore, groupsInOfflineCountAfter); Assert.AreEqual(2, usersFromOfflineStorage.Count()); Assert.AreEqual(1, groupsFromOfflineStorage.Count()); } }
public void TestSmartContext_InsertUsersWithExistingRelatedGroup_AllShouldBeBackedUp() { using (SmartContext sCtx = new SmartContext()) { int usersInOfflineCountBefore = this.offlineContext.Users.Count(); int groupsInOfflineCountBefore = this.offlineContext.Groups.Count(); //The existing related group will actually be backed up the moment //it is retrieved from the SmartContext Group relatedGroup = sCtx.GetSingle<Group>(); User newUser1 = new User() { UserId = 1337, Name = "Mark", Email = "*****@*****.**", Note = "note note note", Income = 15543m }; newUser1.Group = relatedGroup; User newUser2 = new User() { UserId = 1338, Name = "Harry", Email = "*****@*****.**", Note = "note note note", Income = 12543m }; newUser2.Group = relatedGroup; sCtx.Add(newUser1); sCtx.Add(newUser2); sCtx.SaveChanges(); int usersInOfflineCountAfter = this.offlineContext.Users.Count(); int groupsInOfflineCountAfter = this.offlineContext.Groups.Count(); IEnumerable<User> usersFromOfflineStorage = this.offlineContext.Users.Where(usr => usr.UserId == newUser1.UserId || usr.UserId == newUser2.UserId).ToList(); IEnumerable<Group> groupsFromOfflineStorage = this.offlineContext.Groups.Where(grp => grp.GroupId == relatedGroup.GroupId).ToList(); Assert.AreNotEqual(usersInOfflineCountBefore, usersInOfflineCountAfter); Assert.AreNotEqual(groupsInOfflineCountBefore, groupsInOfflineCountAfter); Assert.AreEqual(2, usersFromOfflineStorage.Count()); Assert.AreEqual(1, groupsFromOfflineStorage.Count()); } }