Example #1
0
        public async Task <IActionResult> PutUser(long id, User user)
        {
            if (id != user.UserId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutWheatherDato(int id, WheatherDato wheatherDato)
        {
            if (id != wheatherDato.WheatherDatoID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #3
0
        public async Task <ActionResult <UserDto> > Register(UserDto regUser)
        {
            regUser.Email = regUser.Email.ToLower();
            var emailExist = await _context.User.Where(u =>
                                                       u.Email == regUser.Email).FirstOrDefaultAsync();

            if (emailExist != null)
            {
                return(BadRequest(new { errorMessage = "Email already in use" }));
            }
            User user = new User()
            {
                Email     = regUser.Email,
                FirstName = regUser.FirstName,
                LastName  = regUser.LastName
            };

            user.PwHash = HashPassword(regUser.Password, BcryptWorkfactor);
            _context.User.Add(user);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = user.UserId }, regUser));
        }