public async Task <IActionResult> CreateUser([FromBody] User user) { if (user == null) { return(BadRequest()); } try { user.Password = "******"; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); var userRegistered = await _context.Users.SingleOrDefaultAsync(u => u.Email == user.Email); var userLogged = new UserLoginResponseViewModel() { Id = userRegistered.Id, Name = userRegistered.Name, Email = userRegistered.Email, Token = GenerateToken(), }; return(Ok(userLogged)); } catch (DbUpdateException e) { return(Conflict(e)); } }
public async Task <ActionResult <BillingCycle> > CreateCycle([FromBody] BillingCycle cycle) { if (cycle == null || cycle.Name.Equals(null) || cycle.Month == 0 || cycle.Year == 0) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _context.BillingCyles.AddAsync(cycle); await _context.SaveChangesAsync(); return(Ok()); }