Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("appointmentUserId,applicationUserId,appointmentId")] AppointmentUser appointmentUser)
        {
            if (id != appointmentUser.appointmentUserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(appointmentUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppointmentUserExists(appointmentUser.appointmentUserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(appointmentUser));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("appointmentUserId,applicationUserId,appointmentId")] AppointmentUser appointmentUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(appointmentUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(appointmentUser));
        }
        public async Task <IActionResult> Create([FromBody] CreateViewModel model)
        {
            try
            {
                var user = new AppointmentUser
                {
                    FirstName          = model.FirstName,
                    LastName           = model.LastName,
                    AccessFailedCount  = 0,
                    Email              = model.Email,
                    EmailConfirmed     = false,
                    LockoutEnabled     = true,
                    NormalizedEmail    = model.Email.ToUpper(),
                    NormalizedUserName = model.UserName.ToUpper(),
                    TwoFactorEnabled   = false,
                    UserName           = model.UserName
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await AddToRole(model.UserName, "user");
                    await AddClaims(model.UserName);

                    return(Ok());
                }
                else
                {
                    return(BadRequest(result.Errors.ToArray()));
                }

                return(new JsonResult(result.Errors));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Could not create new user, Ex: {ex}");
            }

            return(BadRequest("Could not create a new user"));
        }