public ActionResult Users_Create([DataSourceRequest]DataSourceRequest request, Volunteer volunteer) { if (this.ModelState.IsValid) { var entity = new Volunteer { UserName = volunteer.UserName, Description = volunteer.Description, Image = volunteer.Image, CreatedOn = volunteer.CreatedOn, ModifiedOn = volunteer.ModifiedOn, IsDeleted = volunteer.IsDeleted, DeletedOn = volunteer.DeletedOn, Email = volunteer.Email, EmailConfirmed = volunteer.EmailConfirmed, PasswordHash = volunteer.PasswordHash, SecurityStamp = volunteer.SecurityStamp, PhoneNumber = volunteer.PhoneNumber, PhoneNumberConfirmed = volunteer.PhoneNumberConfirmed, TwoFactorEnabled = volunteer.TwoFactorEnabled, LockoutEndDateUtc = volunteer.LockoutEndDateUtc, LockoutEnabled = volunteer.LockoutEnabled, AccessFailedCount = volunteer.AccessFailedCount, FirstName = volunteer.FirstName, LastName = volunteer.LastName, Age = volunteer.Age, }; this.db.Users.Add(entity); this.db.SaveChanges(); volunteer.Id = entity.Id; } return this.Json(new[] { volunteer }.ToDataSourceResult(request, this.ModelState)); }
public void Delete(Volunteer model) { this.volunteers.Delete(model); this.volunteers.Save(); }
public void Add(Volunteer model) { this.volunteers.Add(model); this.volunteers.Save(); }
public async Task<ActionResult> RegisterVolunteer(RegisterVolunteerViewModel model) { if (this.ModelState.IsValid) { var user = new Volunteer { UserName = model.UserName, Email = model.Email, Description = model.Description, FirstName = model.FirstName, LastName = model.LastName, Age = model.Age, CreatedOn = DateTime.UtcNow, Image = model.Image }; var result = await this.UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); if (!this.RoleManager.RoleExists(RoleConstants.VolunteerRoleConstant)) { var role = new IdentityRole { Name = RoleConstants.VolunteerRoleConstant }; this.RoleManager.Create(role); } await this.UserManager.AddToRoleAsync(user.Id, RoleConstants.VolunteerRoleConstant); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return this.RedirectToAction("Index", "Home"); } this.AddErrors(result); } // If we got this far, something failed, redisplay form return this.View("Register", model); }
public ActionResult Users_Destroy([DataSourceRequest]DataSourceRequest request, Volunteer volunteer) { this.volunteers.Delete(volunteer.Id); return this.Json(new[] { volunteer }.ToDataSourceResult(request, this.ModelState)); }