Exemplo n.º 1
0
        public async Task <ActionResult <DoctorAdmin> > PostUser(DoctorAdmin duser)
        {
            _context.DoctorAdmins.Add(duser);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUser", new { id = duser.Id }, duser));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> SignUpUser(DocNewUserModel userData)
        {
            var existingUserId = await this.db.DoctorAdmins.FirstOrDefaultAsync(f => f.Username == userData.Username);

            if (existingUserId != null)
            {
                return(BadRequest(new { Message = "Id  already exists" }));
            }

            var duser = new DoctorAdmin
            {
                Username       = userData.Username,
                DoctorId       = userData.DoctorId, //
                HashedPassword = ""
            };
            // hash the password

            var hashed = new PasswordHasher <DoctorAdmin>().HashPassword(duser, userData.Password);

            duser.HashedPassword = hashed;

            this.db.DoctorAdmins.Add(duser);
            await this.db.SaveChangesAsync();

            var rv = new DocAuthService().CreateToken(duser);

            return(Ok(rv));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutUser(int id, DoctorAdmin duser)
        {
            if (id != duser.Id)
            {
                return(BadRequest());
            }

            _context.Entry(duser).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }