public void DeleteByIdSuccess() { var profile = new Profile { Name = "Maria", Email = "*****@*****.**", Password = "******", Role = role, IsActive = true }; profile = profileRepo.EditOrCreate(profile); profiles.Add(profile); profileRepo.Delete(profile.Id); var profileInDatabase = profileRepo.GetById(profile.Id); Assert.IsFalse(profileInDatabase.IsActive); }
public ActionResult Save(Profile profile) { var profileRepo = new ProfileRepository(); Boolean isInsert = profile.Id == 0L; if (isInsert) { //Verifica no banco se já tem um email igual var profileInDB = profileRepo.GetByEmail(profile.Email); //Se existir um e-mail igual e tiver desativado só atribui o id para o objeto e ele irá atualizar para ativo if (profileInDB != null && profileInDB.IsActive == false) { profile.Id = profileInDB.Id; } } try { /** * Adiciona o perfil 2 que é dos participantes dos times, * como só pode ter um admin, não tem como escolher esse perfil**/ var role = new Role { Id = 2 }; profile.IsActive = true; profile.Role = role; profile.Password = CryptoHelper.CryptoPassword(profile.Password); profileRepo.EditOrCreate(profile); return(RedirectToAction("Index")); } catch (SqlException) { ModelState.AddModelError("Email", "Email duplicado!"); ViewBag.IsEdit = false; return(View("Edit", profile)); } }
public void TestInitialize() { DatabaseHelper.CleanDatabase(); roleRepo = new RoleRepository(); profileRepo = new ProfileRepository(); taskRepository = new TaskRepository(); tasks = new List <Task>(); role = new Role { Description = "Team", IsActive = true }; role = roleRepo.EditOrCreate(role); profile = new Profile { Name = "Maria", Email = "*****@*****.**", Password = "******", Role = role, IsActive = true }; profile = profileRepo.EditOrCreate(profile); }