本文整理汇总了C#中UserRepository.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.Delete方法的具体用法?C# UserRepository.Delete怎么用?C# UserRepository.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.Delete方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var dbContext = new ApplicationDbContext();
using (var uow = new UnitOfWork(dbContext))
{
// Creating user
// var user1 = new User { Login = "Anna", Password = "123" };
// var userRepo = new UserRepository(dbContext);
//userRepo.Create(user1);
//uow.Commit();
var userRepo = new UserRepository(dbContext);
var user1 = new User { Login = "Anna1", Password = "123" };
var user2 = new User { Login = "Anna2", Password = "123" };
// userRepo.Create(user1);
//userRepo.Create(user2);
// uow.Commit();
var users = userRepo.GetAll();
Console.WriteLine("All users count: " + users.Count());
var anna = userRepo.GetBy(user1.Login);
userRepo.Delete(anna);
uow.Commit();
users = userRepo.GetAll();
Console.WriteLine("All filtered users count: " + users.Count());
Console.ReadLine();
// Creating user article
var article1 = new Article { Title = "Article1", Body = "Article1 BodyText" };
var anna2 = userRepo.GetBy(user2.Login);
userRepo.Delete(anna2);
// anna2.Articles.Add(article1);
uow.Commit();
/*var comment1 = new Comment { Body = "Article1 is my first arctile. (Anna)" };
var articleRepo = new ArticleRepository(dbContext);
anna2.Comments.Add(comment1);
article1.Comments.Add(comment1);
uow.Commit();*/
}
}
示例2: Delete
public ActionResult Delete(int id)
{
UserRepository userRep = new UserRepository();
userRep.Delete(id);
return RedirectToAction("List");
}
示例3: Execute
public override bool Execute(string input)
{
if (String.IsNullOrEmpty(input)) return false;
var repository = new UserRepository();
int userId;
if (!Int32.TryParse(input, out userId))
{
return false;
}
var user = repository.GetById(userId);
if (user != null)
{
repository.Delete(user);
}
try
{
repository.SaveChanges();
Success = true;
}
catch
{
Success = false;
}
return Success;
}
示例4: AddUser_should_save
public void AddUser_should_save()
{
string username = "save" + Guid.NewGuid();
var user = new User
{
Email = "[email protected]",
FirstName = "john",
IsActive = true,
LastName = "haigh",
PasswordHash = "asdf",
Username = username
};
var svc = new UserService();
svc.AddUser(user);
var repo = new UserRepository();
var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();
// Test
repoUser.ShouldNotBeNull();
// Cleanup user
repo.Delete(repoUser);
repo.Save();
var results2 = repo.Find(u => u.Username == username);
var userFound2 = results2.FirstOrDefault();
Assert.IsNull(userFound2, "Tried to get user but the user was found");
}
示例5: DeleteUser
public bool DeleteUser(int id)
{
UserRepository repo = new UserRepository(entities);
User user = repo.Get(id);
try {
repo.Delete(user);
return true;
}
catch (Exception ex) {
_errorMessage = ex.Message;
return false;
}
}
示例6: Remove_Entity_Test
public static void Remove_Entity_Test()
{
IUserRepository repository = new UserRepository(_session);
ICollection<User> todosAntesDeDelete = repository.GetAll();
foreach (User User in todosAntesDeDelete)
{
repository.Delete(User);
}
ICollection<User> todosDepoisDeDelete = repository.GetAll();
Assert.IsTrue(todosDepoisDeDelete.Count == 0);
}
示例7: Delete
public string Delete()
{
string result = "";
int id = Numerics.GetInt(Request["id"]);
try
{
var repo = new UserRepository();
repo.Delete(id);
result = JsonResult(true, Resources.Messages.Delete);
}
catch (Exception ex)
{
result = JsonResult(false, ex.Message);
}
return result;
}
示例8: delete
public Boolean delete()
{
//delete from user table
String deleteUserID = Request.Params["id"];
int id = int.Parse(deleteUserID);
IRepository<User> repository = new UserRepository();
User deletedUser = repository.findById(id);
if (deletedUser == null)
{
return false;
}
repository.Delete(deletedUser);
//delete from asp.netUser table
var context = new NetCafeWeb.Models.ApplicationDbContext();
var UserManager = new UserManager<NetCafeWeb.Models.ApplicationUser>(new UserStore<NetCafeWeb.Models.ApplicationUser>(context));
ApplicationUser aspSelectedUser = context.Users.Where(u => u.UserName.Equals((deletedUser.UserName), StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
UserManager.DeleteAsync(aspSelectedUser);
return true;
}
示例9: DeleteUser
public static BaseActionResult DeleteUser(User obj4delete)
{
using (var context = new XiaoluEntities())
{
string msg;
var repository = new UserRepository(context);
if (obj4delete == null)
{
msg = string.Format(XiaoluResources.MSG_DELETE_SUCCESS, XiaoluResources.STR_USER) + string.Format(XiaoluResources.STR_FAIL_RESAON, XiaoluResources.MSG_OBJECT_IS_NULL);
return new BaseActionResult(false, msg);
}
repository.Delete(obj4delete);
context.SaveChanges();
msg = string.Format(XiaoluResources.MSG_UPDATE_SUCCESS, obj4delete.Name);
return new BaseActionResult(true, msg);
}
}
示例10: AddUser_should_save_with_user_properties
public void AddUser_should_save_with_user_properties()
{
string username = "save_with_user_propertie" + Guid.NewGuid();
var user = new User
{
Email = "[email protected]",
FirstName = "john",
IsActive = true,
LastName = "haigh",
PasswordHash = "asdf",
Username = username
};
var svc = new UserService();
svc.AddUser(user);
var repo = new UserRepository();
var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();
// Test
repoUser.Email.ShouldEqual(user.Email);
repoUser.FirstName.ShouldEqual(user.FirstName);
repoUser.LastName.ShouldEqual(user.LastName);
repoUser.IsActive.ShouldEqual(user.IsActive);
repoUser.PasswordHash.ShouldEqual(user.PasswordHash);
repoUser.Username.ShouldEqual(user.Username);
// Cleanup user
repo.Delete(repoUser);
repo.Save();
var results2 = repo.Find(u => u.Username == username);
var userFound2 = results2.FirstOrDefault();
userFound2.ShouldBeNull();
}
示例11: GetUserByUsername_should_getuser
public void GetUserByUsername_should_getuser()
{
string username = "getbyusername" + Guid.NewGuid();
var user = new User
{
Email = "[email protected]",
FirstName = "john",
IsActive = true,
LastName = "haigh",
PasswordHash = "asdf",
Username = username
};
var svc = new UserService();
svc.AddUser(user);
// main test
var userAssert = svc.GetUserByUsername(username);
userAssert.ShouldNotBeNull();
// Assert
var repo = new UserRepository();
var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();
// Cleanup user
repo.Delete(repoUser);
repo.Save();
var results2 = repo.Find(u => u.Username == username);
var userFound2 = results2.FirstOrDefault();
userFound2.ShouldBeNull();
}
示例12: DELRow
private void DELRow(int id)
{
try
{
using (var db = new CSBCDbContext())
{
var rep = new UserRepository(db);
var user = new User();
rep.Delete(rep.GetById(id));
}
}
catch (Exception ex)
{
lblError.Text = "DELRow::" + ex.Message;
}
}
示例13: DeleteUser
public void DeleteUser()
{
using (var uow = new CapriconContext())
{
var userRep = new UserRepository(uow);
var existingUser = userRep.Find(u => u.UserId == 2).FirstOrDefault();
Assert.IsNotNull(existingUser);
int userId;
if (existingUser != null)
{
userId = existingUser.UserId;
//Delete employee
userRep.Delete(existingUser);
try
{
uow.SaveChanges();
}
catch (DbEntityValidationException ex)
{
//Retrieve validation errors
ex.EntityValidationErrors.ToList().ForEach
(
v =>
{
v.ValidationErrors.ToList().ForEach
(
e =>
{
System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
}
);
}
);
Assert.Fail("Test failed");
}
Assert.IsNull(userRep.Find(u => u.UserId == userId).FirstOrDefault());
}
else //no userss were selected
Assert.Fail("No user was selected");
}
}