public void CreateUser(User newUser) { using (var manager = new DataManager()) { manager.Context.Users.AddObject(newUser); manager.Context.SaveChanges(); MessagesSender Sender = new MessagesSender(); Sender.Send(newUser); } }
public ActionResult Create(User user) { if (ModelState.IsValid) { _userService.CreateUser(user); return RedirectToAction("Index"); } return View(user); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { //db.Users.Attach(user); //db.ObjectStateManager.ChangeObjectState(user, EntityState.Modified); //db.SaveChanges(); _userService.EditUser(user); return RedirectToAction("Index"); } return View(user); }
public void EditUser(User user) { using (var manager = new DataManager()) { User editedUser = new User { UserId = user.UserId }; manager.Context.Users.Attach(editedUser); editedUser.FirstName = user.FirstName; editedUser.LastName = user.LastName; editedUser.UserName = user.UserName; editedUser.Email = user.Email; manager.Context.SaveChanges(); } }
public void Send(User user) { SmtpClient Smtp = new SmtpClient("smtp.gmail.com", 587); Smtp.Credentials = new NetworkCredential("*****@*****.**","AllForHome"); Smtp.EnableSsl = true; MailMessage Message = new MailMessage(); Message.From = new MailAddress("*****@*****.**"); Message.To.Add(user.Email); Message.Subject = "Тема"; Message.Body = Parse(user,2); Smtp.Send(Message); }
private string Parse(User user, int languageLetterId) { using (var manager = new DataManager()) { string ParsedText = manager.Context.LanguageLetters.SingleOrDefault(u => u.LanguageLetterId == languageLetterId).Template; Dictionary<string, string> PatternsAndValues = new Dictionary<string, string>() { {"{fullname}", user.FirstName+" "+user.LastName}, {"{username}", user.UserName} }; foreach (var pair in PatternsAndValues) { Regex RegularExpression = new Regex(pair.Key); ParsedText = RegularExpression.Replace(ParsedText, pair.Value); } return ParsedText; } }
private void FixupUser(User previousValue) { if (previousValue != null && previousValue.Projects.Contains(this)) { previousValue.Projects.Remove(this); } if (User != null) { if (!User.Projects.Contains(this)) { User.Projects.Add(this); } if (ProjectManagerId != User.UserId) { ProjectManagerId = User.UserId; } } else if (!_settingFK) { ProjectManagerId = null; } }
private void FixupUser(User previousValue) { if (previousValue != null && previousValue.Tasks.Contains(this)) { previousValue.Tasks.Remove(this); } if (User != null) { if (!User.Tasks.Contains(this)) { User.Tasks.Add(this); } if (AssigneeId != User.UserId) { AssigneeId = User.UserId; } } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { User addedUser = new User {FirstName=model.FirstName, LastName=model.LastName, UserName=model.UserName, Email=model.Email, AspnetUserId=_userService.GetAspUser(model.UserName).UserId}; _userService.CreateUser(addedUser); FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }