public ActionResult Entry(ParticipantEntryVm model) { if (ModelState.IsValid) { var participant = Mapper.Map <Participant>(model); bool isAdded = _participantManager.Add(participant); if (isAdded) { return(RedirectToAction("Index")); } } return(RedirectToAction("Entry")); }
public ActionResult Entry(ParticipantCreateVm entity) { HttpPostedFileBase file = Request.Files["uploadImage"]; if (file != null) { entity.Image = ConvertToBytes(file); if (ModelState.IsValid) { var participant = Mapper.Map <Participant>(entity); var participants = _participantManager.GetAllParticipants(); if (participants.FirstOrDefault(x => x.RegNo == participant.RegNo) != null) { ViewBag.Message = "Exist"; entity.OrganizationSelectListItems = GetAllOrganizationSlItems(); entity.CourseSelectListItems = GetAllCourseSlItems(); entity.BatchSelectListItems = GetAllBatchSlItems(); return(View(entity)); } else { bool isAdded = _participantManager.Add(participant); if (isAdded) { ModelState.Clear(); ViewBag.Message = "Saved"; var model = new ParticipantCreateVm() { OrganizationSelectListItems = GetAllOrganizationSlItems(), CourseSelectListItems = GetAllCourseSlItems(), BatchSelectListItems = GetAllBatchSlItems() }; return(View(model)); } } } } ModelState.AddModelError("", "An Unknown Error Occured!"); entity.OrganizationSelectListItems = GetAllOrganizationSlItems(); entity.CourseSelectListItems = GetAllCourseSlItems(); entity.BatchSelectListItems = GetAllBatchSlItems(); return(View(entity)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { Participant participant = new Participant { Username = model.Username, Email = user.Email, ApplicationUserId = user.Id }; ParticipantManager.Add(participant); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // 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>"); //add the name to the session Session["participantID"] = participant.Id; return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }