// GET: Member/Create public IActionResult Create() { var model = new MemberCreateViewModel { State = "UT", Status = "Active", WhenJoined = DateTime.Now, WhenExpires = DateTime.Now.AddYears(1) }; var chapterSelect = new List <SelectListItem> { new SelectListItem { Value = "0", Text = "None" } }; var chapters = _context.Chapters.OrderBy(c => c.Name).ToList(); foreach (var chapter in chapters) { chapterSelect.Add(new SelectListItem { Value = chapter.Id.ToString(), Text = chapter.Name }); } model.Chapters = chapterSelect; return(View(model)); }
/// <summary> /// 從ViewModel轉為User Entity /// </summary> /// <param name="model">新增會員ViewModel</param> /// <param name="picPath">The pic path.</param> /// <returns>User Entity</returns> public User ConvertToUserEntity(MemberCreateViewModel model, string picPath) { return(new User { Guid = Guid.NewGuid().ToString(), IsAdmin = false, Mail = model.Mail, Name = model.Name, Pic = picPath, IsDel = false }); }
// GET: Member/Create public async Task <IActionResult> Create() { ViewBag.User = await GetCurrentUser(); var personTypes = await _context.PersonTypes.OrderBy(p => p.Name).ToListAsync(); var model = new MemberCreateViewModel { State = "UT", Status = "Active", IsSaveAndNew = false, WhenJoined = DateTime.Now, WhenExpires = DateTime.Now.AddYears(1), PersonTypeId = personTypes.FirstOrDefault(p => p.IsMemberDefault).Id }; var chapterSelect = new List <SelectListItem> { new SelectListItem { Value = "0", Text = "None" } }; var chapters = _context.Chapters.OrderBy(c => c.Name).ToList(); foreach (var chapter in chapters) { chapterSelect.Add(new SelectListItem { Value = chapter.Id.ToString(), Text = chapter.Name }); } model.Chapters = chapterSelect; var personTypesSelect = new List <SelectListItem>(); foreach (var pt in personTypes) { personTypesSelect.Add(new SelectListItem { Value = pt.Id.ToString(), Text = pt.Name }); } model.PersonTypes = personTypesSelect; return(View(model)); }
public IActionResult Add(MemberCreateViewModel model) { if (ModelState.IsValid) { Member member = new Member { Name = model.Name, Phone = model.Phone, Position = model.Position, }; repository.Add(member); var url = Url.Action("Read", new { id = member.Id }); return(Created(url, member)); } return(BadRequest(ModelState)); }
public async Task Create_WhenCalled_CreateMemberInDbAndRedirectToIndex() { // Arrange var model = new MemberCreateViewModel { FirstName = "Andy", LastName = "King", Phone = "134 2456 7890", Email = "*****@*****.**" }; // Act var result = await controller.Create(model) as RedirectToActionResult; // Assert repository.Verify(r => r.AddAsync(It.IsAny <Member>()), Times.Once); Assert.That(result.ActionName, Is.EqualTo("index").IgnoreCase); }
protected override DriverResult Editor(MemberPart part, IUpdateModel updater, dynamic shapeHelper) { var controller = (Controller)updater; if (controller.RouteData.CheckAction(Actions.Create)) { //Step 1. Validate all inputs. var createModel = new MemberCreateViewModel { Member = part }; if (updater.TryUpdateModel(createModel, Prefix, null, null)) { //Step 2. Create user. if (!Regex.IsMatch(createModel.User.Email ?? "", UserPart.EmailPattern, RegexOptions.IgnoreCase)) { // http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx updater.AddModelError("Email", T("You must specify a valid email address.")); } else if (createModel.User.Password != createModel.User.ConfirmPassword) { updater.AddModelError("ConfirmPassword", T("Password confirmation must match.")); } else if (!_userService.VerifyUserUnicity(createModel.User.Email, createModel.User.Email)) { updater.AddModelError("NotUniqueUserName", T("User with that email already exists.")); } else if (controller.ModelState.IsValid) { IUser user = _membershipService.CreateUser(new CreateUserParams(createModel.User.Email, createModel.User.Password, createModel.User.Email, null, null, true)); //Step 2. Update userid on member. part.Record.UserId = user.Id; } } } else { var editModel = new MemberEditViewModel { Member = part }; //todo: update email. updater.TryUpdateModel(editModel, Prefix, null, null); } return(Editor(part, shapeHelper)); }
public async Task <IActionResult> Create(MemberCreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName = ProcessUploadedFile(model.Photo); Member member = new Member { Name = model.Name, Phone = model.Phone, Position = model.Position, PhotoPath = uniqueFileName }; await repository.Add(member); return(RedirectToAction("list", "member")); } return(View()); }
/// <summary> /// 新增網站會員 /// </summary> /// <param name="model">The model.</param> /// <param name="path">存放大頭照的實體路徑</param> public void CreateUser(MemberCreateViewModel model, string path) { using (var tranScope = new TransactionScope()) { // Table User var fileName = SaveMemberPic(model.File, path); var user = ConvertToUserEntity(model, $"{FileUploadPath}/{fileName}"); user.Id = _userRepo.Create(_conn, user); var userVm = ConvertToUserViewModel(user); // Table Password var password = ConvertToPassEntity(user.Id, user.Guid, model.Password); CreatePassword(password); // 註冊完直接給他登入-因為是新會員,所以文章count直接給預設0即可 SignInUser.UserLogin(true, userVm, new UserArticleCount()); tranScope.Complete(); } }
public async Task <IActionResult> Post( [FromBody] MemberCreateViewModel model, [FromHeader(Name = "x-requestid")] string requestId) { var member = new Member { Id = Guid.NewGuid().ToString(), Address = model.Address, BirthDate = model.BirthDate, BirthPlace = model.BirthPlace, CardNumber = model.CardNumber, MothersName = model.MothersName, Name = model.Name }; context.Members.Add(member); await context.SaveChangesAsync(); return(Ok(member.Id)); }
public ActionResult Create(MemberCreateViewModel viewModel) { var defaultPassword = Util.RandomString(); var Member = new tblmember() { BusinessRegNo = viewModel.BusinessRegNo, CompanyName = viewModel.CompanyName, PICName = viewModel.PICName, PICContact = viewModel.PICContact, PICEmail = viewModel.PICEmail, OfficeContact = "-", Address = viewModel.Address, Postcode = viewModel.Postcode, State = viewModel.State, Country = viewModel.Country, Roles = viewModel.Roles, Password = Util.GetMD5Hash(defaultPassword), CreateDT = DateTime.Now, Language = "EN", Active = true }; db.tblmembers.Add(Member); db.SaveChanges(); var emailBody = string.Format(@"Hi {0}, <br /><br /> Thanks for Subscribing to the EZ Go Holiday Website ! You’re joining an amazing community of folks who love nerding out about travelling. <br /><br /> As you wait for the next issue, check out some of our most popular posts. They’re a great place to get started. <br /><br /> Website: http://www.ezgoholiday.com <br /> Username: {1} <br /> Password: {2} <br /><br /> Have an awesome day! <br /> EZ Go Holiday Management", viewModel.PICName, viewModel.PICEmail, defaultPassword); Util.SendEmail("Welcome to EZ Go Holiday!", emailBody, viewModel.PICEmail, "", ""); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(MemberCreateViewModel model) { if (ModelState.IsValid) { var member = new Member { FirstName = model.FirstName, LastName = model.LastName, Phone = model.Phone, Email = model.Email, DateRegistered = DateTime.Now }; await repository.AddAsync(member); await unitOfWork.CompleteAsync(); return(RedirectToAction(nameof(Index))); } return(View()); }
public IActionResult Create(MemberCreateViewModel memberCreateViewModel) { if (ModelState.IsValid) { Member member = new Member { MemberNumber = memberCreateViewModel.MemberNumber, ParentName = memberCreateViewModel.ParentName, ChildName = memberCreateViewModel.ChildName, ExpiryYear = memberCreateViewModel.ExpiryYear, Type = memberCreateViewModel.Type }; this.memberRepository.Create(member); TempData["Message"] = $"{member.ParentName} is aangemaakt"; return(RedirectToAction("Leden", "Gezinsbond")); } else { return(View()); } }
public ActionResult Create(MemberCreateViewModel model) { ViewBag.Title = "新增會員"; if (!ModelState.IsValid) { return(View(model)); } var isExistSameUser = _memberService.CheckUserExist(model.Mail); if (isExistSameUser) { ModelState.AddModelError("SameUser", $"{model.Mail} 已被註冊,若忘記密碼請洽系統管理員。"); return(View(model)); } var picPath = Server.MapPath(FileUploadPath); _memberService.CreateUser(model, picPath); return(RedirectToAction("Index", "Post")); }
public async Task <IActionResult> Create([Bind("City,Email,FirstName,LastName,State,Street1,Street2,Zip,Phone,Email,Note,WhenJoined,WhenExpires,Status,Chapter1,Chapter2")] MemberCreateViewModel viewModel) { if (ModelState.IsValid) { var applicationUser = new ApplicationUser { City = viewModel.City, Email = viewModel.Email, FirstName = viewModel.FirstName, LastName = viewModel.LastName, State = viewModel.State, Street1 = viewModel.Street1, ZipCode = viewModel.Zip, PhoneNumber = viewModel.Phone, WhenJoined = viewModel.WhenJoined, WhenExpires = viewModel.WhenExpires, Status = viewModel.Status }; _context.Add(applicationUser); await _context.SaveChangesAsync(); if (!string.IsNullOrEmpty(viewModel.Note)) { var note = new ApplicationUserNote { ApplicationUserId = applicationUser.Id, WhenAdded = DateTime.Now, Note = viewModel.Note }; _context.Add(note); } if (viewModel.Chapter1 != 0) { _context.Add(new MemberChapter { ApplicationUserId = applicationUser.Id, ChapterId = viewModel.Chapter1, WhenJoined = DateTime.Now }); } if (viewModel.Chapter2 != 0) { _context.Add(new MemberChapter { ApplicationUserId = applicationUser.Id, ChapterId = viewModel.Chapter2, WhenJoined = DateTime.Now }); } await _context.SaveChangesAsync(); Response.Cookies.Append("FlashSuccess", "Member " + applicationUser.FirstName + " " + applicationUser.LastName + " was successfully saved"); return(RedirectToAction("Index")); } var chapterSelect = new List <SelectListItem> { new SelectListItem { Value = "0", Text = "None" } }; var chapters = _context.Chapters.OrderBy(c => c.Name).ToList(); foreach (var chapter in chapters) { chapterSelect.Add(new SelectListItem { Value = chapter.Id.ToString(), Text = chapter.Name }); } viewModel.Chapters = chapterSelect; return(View(viewModel)); }
public async Task <IActionResult> Create([Bind("City,Email,FirstName,LastName,State,Street1,Street2,Zip,Phone,Email,Note,WhenJoined,WhenExpires,Chapter,PersonTypeId,IsSaveAndNew,Pseudonym,ContactName")] MemberCreateViewModel viewModel) { ViewBag.User = await GetCurrentUser(); if (_context.ApplicationUser.Any(a => a.Email == viewModel.Email)) { ModelState.AddModelError("Email", "Email already in use"); } var personTypes = await _context.PersonTypes.OrderBy(p => p.Name).ToListAsync(); if (ModelState.IsValid) { var applicationUser = new ApplicationUser { City = viewModel.City, Email = viewModel.Email, FirstName = viewModel.FirstName, LastName = viewModel.LastName, Pseudonym = viewModel.Pseudonym, ContactName = viewModel.ContactName, State = viewModel.State, Street1 = viewModel.Street1, ZipCode = viewModel.Zip, PhoneNumber = viewModel.Phone, WhenJoined = viewModel.WhenJoined, WhenExpires = viewModel.WhenExpires, Status = viewModel.Status, UserName = viewModel.Email, PersonTypeId = viewModel.PersonTypeId }; var result = await _userManager.CreateAsync(applicationUser, "1We%1We%" + DateTime.UtcNow.ToString()); if (!string.IsNullOrEmpty(viewModel.Note)) { var note = new ApplicationUserNote { ApplicationUserId = applicationUser.Id, AddedBy = ViewBag.User, WhenAdded = DateTime.Now, Note = viewModel.Note }; _context.Add(note); } if (viewModel.Chapter != 0) { _context.Add(new MemberChapter { ApplicationUserId = applicationUser.Id, ChapterId = viewModel.Chapter, WhenJoined = DateTime.Now }); } var personType = personTypes.FirstOrDefault(p => p.Id == viewModel.PersonTypeId); await _userManager.AddToRoleAsync(applicationUser, personType.Name); await _context.SaveChangesAsync(); if (viewModel.IsSaveAndNew) { return(RedirectToAction("Create")); } return(RedirectToAction("Index")); } var chapterSelect = new List <SelectListItem> { new SelectListItem { Value = "0", Text = "None" } }; var chapters = _context.Chapters.OrderBy(c => c.Name).ToList(); foreach (var chapter in chapters) { chapterSelect.Add(new SelectListItem { Value = chapter.Id.ToString(), Text = chapter.Name }); } viewModel.Chapters = chapterSelect; viewModel.IsSaveAndNew = false; var personTypesSelect = new List <SelectListItem>(); foreach (var pt in personTypes) { personTypesSelect.Add(new SelectListItem { Value = pt.Id.ToString(), Text = pt.Name }); } viewModel.PersonTypes = personTypesSelect; return(View(viewModel)); }
public async Task <IActionResult> Post([FromBody] MemberCreateViewModel model) { return(Ok()); }