示例#1
0
        public ActionResult Post(UserDto userDto)
        {
            var user = new User {
                FirstName = userDto.FirstName, LastName = userDto.LastName
            };

            _StickyNotes.Users.Add(user);
            _StickyNotes.SaveChanges();
            return(CreatedAtAction("Get", new { id = user.Id }, user));
        }
示例#2
0
        public ActionResult Post(Guid userId, StickyNoteDto stickyNoteDto)
        {
            var stickyNote = new StickyNote {
                Title = stickyNoteDto.Title, Note = stickyNoteDto.Note, UserId = userId, Id = Guid.NewGuid()
            };

            _stickyNotes.StickyNotes.Add(stickyNote);
            _stickyNotes.SaveChanges();
            return(CreatedAtAction("Get", new { id = stickyNote.Id, userId }, stickyNote));
        }
 public void Save()
 {
     _context.SaveChanges();
 }
 public async Task SaveUser(Users user)
 {
     _context.Users.Add(user);
     _context.SaveChanges();
 }
示例#5
0
        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)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    var db = new StickyNotesContext();
                    var newTeam = new Team
                    {
                        Name = model.TeamName,
                        AdminId = user.Id
                    };
                    var newUser = new User
                    {
                        EmailAddress = model.Email,
                        UserName = model.UserName,
                        Team = newTeam,
                        TeamId = newTeam.Id
                    };

                    db.User.Add(newUser);
                    db.Team.Add(newTeam);
                    db.SaveChanges();

                    // 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 RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
示例#6
0
        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);

            // this needs to change
            var db = new StickyNotesContext();
            var userTeam = new User
            {
                EmailAddress = model.Email,
                TeamId = model.TeamId
            };

            db.User.Add(userTeam);
            db.SaveChanges();

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok();
        }