public async Task <IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(GetErrorResult(result)); } await UserManager.AddToRoleAsync(user.Id, RoleNames.User); var buddyCreate = new BuddyCreate { Name = model.Name, CurrentLocation = model.CurrentLocation, IsMale = model.IsMale, Age = model.Age }; var service = new BuddyService(Guid.Parse(user.Id)); service.CreateBuddy(buddyCreate); return(Ok()); }
// Create public IHttpActionResult Post(BuddyCreate buddy) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateBuddyService(); if (!service.CreateBuddy(buddy)) { return(InternalServerError()); } return(Ok()); }
public ActionResult Create(BuddyCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateBuddyService(); if (service.CreateBuddy(model)) { TempData["SaveResult"] = "Your profile was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Profile could not be created"); return(View(model)); }
public bool CreateBuddy(BuddyCreate model) { var entity = new Buddy { UserId = _userId, Name = model.Name, CurrentLocation = model.CurrentLocation, IsApproved = model.IsApproved, IsMale = model.IsMale, Age = model.Age }; using (var ctx = new ApplicationDbContext()) { ctx.Buddies.Add(entity); return(ctx.SaveChanges() == 1); } }