本文整理汇总了C#中UserRepository.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.SaveChanges方法的具体用法?C# UserRepository.SaveChanges怎么用?C# UserRepository.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.SaveChanges方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeStatus
public string ChangeStatus()
{
string result = "";
try
{
int id = 0;
int.TryParse(Request["id"], out id);
byte status = 0;
byte.TryParse(Request["status"], out status);
var repo = new UserRepository();
var v = repo.GetByID(id);
if (v != null)
{
v.RecordStatus = status;
repo.SaveChanges();
}
result = JsonResult(true, Resources.Messages.StatusChanged);
}
catch (Exception ex)
{
result = JsonResult(false, ex.Message);
}
return result;
}
示例2: 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;
}
示例3: InsertUserCheckUnique
public void InsertUserCheckUnique()
{
var unitOfWork = new UnitOfWork<GenericRepositoryTestContext>();
var user = new User
{
Email = "[email protected]",
Name = "Wim Pool"
};
var userRepo = new UserRepository(unitOfWork);
userRepo.Add(user);
try
{
userRepo.SaveChanges();
}
catch (DbEntityValidationException validationException)
{
foreach (var error in validationException.EntityValidationErrors)
{
Assert.IsTrue(error.ValidationErrors.Count == 1);
Assert.AreEqual(error.ValidationErrors.First().ErrorMessage, "NotUnique");
Assert.AreEqual(error.ValidationErrors.First().PropertyName, "Email");
}
}
var users = userRepo.FindBy(u => u.Email == "[email protected]");
Assert.IsTrue(users.Count() == 1);
}
示例4: RemoveCommentFromUserException
public void RemoveCommentFromUserException()
{
var unitOfWork = new UnitOfWork<GenericRepositoryTestContext>();
var userRepo = new UserRepository(unitOfWork);
var user = userRepo.GetFirst(u => u.Email == "[email protected]");
var comment = user.Comments.FirstOrDefault();
user.Comments.Remove(comment);
userRepo.SaveChanges();
}
示例5: RemoveCommentFromPost
public void RemoveCommentFromPost()
{
var unitOfWork = new UnitOfWork<GenericRepositoryTestContext>();
Assert.IsTrue(unitOfWork.Entities.Comments.Count() == 2);
var userRepo = new UserRepository(unitOfWork);
var user = userRepo.GetFirst(u => u.Email == "[email protected]");
var post = user.Posts.FirstOrDefault();
Debug.Assert(post != null, "post != null");
var comment = post.Comments.FirstOrDefault(c => c.User == user);
post.Comments.Remove(comment);
userRepo.SaveChanges();
Assert.IsTrue(unitOfWork.Entities.Comments.Count() == 1);
}
示例6: Main
static void Main(string[] args)
{
using (var context = new CmsDBcontext())
{
UserRepository repository = new UserRepository(context);
var userRoleRepository = new Repository<UserRole>(context);
var role = userRoleRepository.GetById(2);
repository.RegisterInsert(new User()
{
NickName = "xuyy",
Sex = false,
Password = "123456",
Role = role
});
repository.RegisterInsert(new User()
{
NickName = "liuyin",
Sex = false,
Password = "123456",
Role = role
});
repository.SaveChanges();
}
}
示例7: Save
public string Save()
{
string result = "";
try
{
var repo = new UserRepository();
var userInput = JsonConvert.DeserializeObject<DAL.User>(Request["user"]);
if (userInput != null)
{
if (repo.IsExist(userInput.ID, userInput.UserName))
return JsonResult(false, "1");
else
{
if (userInput.ID == 0)
repo.Add(userInput);
else
{
var user = repo.GetByID(userInput.ID);
if (user != null)
{
user.UserName = userInput.UserName;
user.RoleID = userInput.RoleID;
user.RoleName = userInput.RoleName;
if (userInput.Password + "" != "")
user.Password = userInput.Password;
repo.SaveChanges();
}
}
result = JsonResult(true, Resources.Messages.Save);
}
}
else
result = JsonResult(true, Resources.Messages.Save);
}
catch (Exception ex)
{
result = JsonResult(false, ex.Message);
}
return result;
}