public async Task <IActionResult> PostUsers(CreateUserRequest request) { UsersReponse usersReponse = new UsersReponse(); usersReponse.user = new Kwanso.Core.Contracts.ViewModels.UsersViewModel(); try { var checkEmail = _context.Users.Any(x => x.Email == request.Email); if (checkEmail == true) { usersReponse.status_code = 409; usersReponse.error = "Email already exist"; return(Conflict(new Response <UsersReponse>(usersReponse))); } Users user = new Users(); user.Email = request.Email; user.Password = PasswordHasher.HashPassword(request.Password); user.CreatedAt = DateTime.Now; _context.Users.Add(user); await _context.SaveChangesAsync(); usersReponse.status_code = 200; usersReponse.user = _mapper.Map <UsersViewModel>(user); return(Ok(new Response <UsersReponse>(usersReponse))); } catch (Exception ex) { usersReponse.error = ex.Message; usersReponse.status_code = 400; return(BadRequest(new Response <UsersReponse>(usersReponse))); } }
public async Task <IActionResult> PostTasks(CreateTaskRequest request) { TasksResponse tasksResponse = new TasksResponse(); tasksResponse.task = new Kwanso.Core.Contracts.ViewModels.TaskViewModel(); try { Kwanso.Core.Models.Tasks task = new Tasks(); task.Name = request.Name; task.IsActive = true; _context.Tasks.Add(task); await _context.SaveChangesAsync(); tasksResponse.status_code = 200; tasksResponse.task = _mapper.Map <TaskViewModel>(task); return(Ok(new Response <TasksResponse>(tasksResponse))); } catch (Exception ex) { tasksResponse.error = ex.Message; tasksResponse.status_code = 400; return(BadRequest(new Response <TasksResponse>(tasksResponse))); } }