本文整理汇总了C#中GenericRepository.Save方法的典型用法代码示例。如果您正苦于以下问题:C# GenericRepository.Save方法的具体用法?C# GenericRepository.Save怎么用?C# GenericRepository.Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericRepository
的用法示例。
在下文中一共展示了GenericRepository.Save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public async Task<ActionResult> Register([Bind(Include = "FirstName, GivenName, Email")] RegisterViewModel model)
{
try
{
if (!ModelState.IsValid)
{
return View(model);
}
User user = new User();
UserDetails userDetails = new UserDetails();
//user.Password = model.Password;
user.Email = model.Email;
user.DateCreated = DateTime.UtcNow;
user.DateLastUpdated = DateTime.UtcNow;
user.UserDetails = new UserDetails();
user.UserDetails.FirstName = model.FirstName;
user.UserDetails.GivenName = model.GivenName;
user.UserDetails.Email = model.Email;
user.UserDetails.DateCreated = DateTime.UtcNow;
user.UserDetails.DateLastUpdated = DateTime.UtcNow;
using (var db = NannyContext.Create())
{
GenericRepository<Models.User> repository = new GenericRepository<Models.User>(db);
repository.Insert(user);
repository.Save();
}
EmailHelper emailHelper = new EmailHelper();
emailHelper.Send(user.Id.ToString(), user.UserDetails.FirstName, user.Email);
return View("RegisterSuccess");
}
catch (DataException dex)
{
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
}
return View(model);
}
示例2: ConfirmRegister
public async Task<ActionResult> ConfirmRegister()
{
ConfirmRegisterViewModel viewModel = new ConfirmRegisterViewModel();
try
{
String uid = this.Request.QueryString["uid"];
if (uid.IsNullOrBlank())
{
viewModel.Message = "User not exist";
return View(viewModel);
}
using (var db = NannyContext.Create())
{
GenericRepository<Models.User> repository = new GenericRepository<Models.User>(db);
Guid idUser = new Guid(uid);
User user = repository.GetByID(idUser);
if (user == null)
{
viewModel.Message = "User not exist";
}
else if (user.DateConfirmEmail == null)
{
user.DateConfirmEmail = DateTime.UtcNow;
repository.Update(user);
repository.Save();
viewModel.IdUser = idUser.ToString();
viewModel.Message = "Thank you for confirming your email";
}
else if (user.DateConfirmEmail != null)
{
viewModel.Message = "User already";
}
}
return View(viewModel);
}
catch (DataException dex)
{
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
}
return View();
}
示例3: Edit
public async Task<ActionResult> Edit([Bind(Include = "Id, FirstName, GivenName, Password, ConfirmPassword, Email, BirthDate, Description, IdGender, Postcode, IdSuburb, AddressLine1, AddressLine2, MobilePhone, HomePhone, AgreeEmailNews")] Nanny.Models.Nanny model)
{
Models.Nanny nanny = null;
try
{
if (!ModelState.IsValid)
{
return View(model);
}
using (var db = NannyContext.Create())
{
GenericRepository<Models.Nanny> repository = new GenericRepository<Models.Nanny>(db);
// nanny = repository.GetByID(model.Id);
//nanny.FirstName = model.FirstName != nanny.FirstName ? model.FirstName : nanny.FirstName;
//nanny.GivenName = model.GivenName != nanny.GivenName ? model.GivenName : nanny.GivenName;
//nanny.Email = model.Email != nanny.Email ? model.Email : nanny.Email;
//nanny.Description = model.Description != nanny.Description ? model.Description : nanny.Description;
//nanny.BirthDate = model.BirthDate != nanny.BirthDate ? model.BirthDate : nanny.BirthDate;
nanny.Postcode = model.Postcode != nanny.Postcode ? model.Postcode : nanny.Postcode;
nanny.IdSuburb = model.IdSuburb != nanny.IdSuburb ? model.IdSuburb : nanny.IdSuburb;
nanny.AddressLine1 = model.AddressLine1 != nanny.AddressLine1 ? model.AddressLine1 : nanny.AddressLine1;
nanny.AddressLine2 = model.AddressLine2 != nanny.AddressLine2 ? model.AddressLine2 : nanny.AddressLine2;
nanny.MobilePhone = model.MobilePhone != nanny.MobilePhone ? model.MobilePhone : nanny.MobilePhone;
nanny.HomePhone = model.HomePhone != nanny.HomePhone ? model.HomePhone : nanny.HomePhone;
nanny.IdGender = model.IdGender != nanny.IdGender ? model.IdGender : nanny.IdGender;
model.DateLastUpdated = DateTime.UtcNow;
repository.Update(nanny);
repository.Save();
ViewBag.Genders = new GenericRepository<Gender>(db).Get();
ViewBag.Suburbs = new GenericRepository<Suburb>(db).Get();
}
return PartialView("Basic", nanny);
}
catch (DataException dex)
{
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
}
return View(model);
}
示例4: AddLanguageSkill
public async Task<ActionResult> AddLanguageSkill([Bind(Include = "IdNanny, IdLanguage, IdLanguageLevel")] LanguageSkill model)
{
try
{
if (!ModelState.IsValid)
{
return PartialView("Profile");
}
model.DateCreated = DateTime.UtcNow;
model.DateLastUpdated = DateTime.UtcNow;
GenericRepository<LanguageSkill> repositoryqLanguageSkill = new GenericRepository<LanguageSkill>(new NannyContext());
repositoryqLanguageSkill.Insert(model);
repositoryqLanguageSkill.Save();
IEnumerable<LanguageSkill> languages = repositoryqLanguageSkill.Get().Where(l => l.IdNanny == model.IdNanny).ToList();
ViewBag.LanguageSkills = languages;
return GetMenu("LanguageSkill");
}
catch (DataException dex)
{
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
}
return View(model);
}
示例5: ConfirmRegisterPassword
public async Task<ActionResult> ConfirmRegisterPassword([Bind(Include = "Password, IdUser")] ConfirmRegisterViewModel model)
{
try
{
if (!ModelState.IsValid)
{
return View(model);
}
using (var db = NannyContext.Create())
{
GenericRepository<Models.User> repository = new GenericRepository<Models.User>(db);
User user = repository.GetByID(model.IdUser);
user.Password = model.Password;
repository.Update(user);
repository.Save();
}
return View();
}
catch (DataException dex)
{
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
}
return View();
}