public async Task <ResultModel <UserDTO> > Authenticate(string username, string password) { ResultModel <UserDTO> result = new ResultModel <UserDTO>(); try { var data = await _context.Users.Where(x => x.Username == username).FirstOrDefaultAsync(); if (data != null) { //verify password if (BCrypt.Net.BCrypt.Verify(password, data.Password)) { var model = _mapper.Map <UserDTO>(data); result.SetSuccess("success", model); } else { result.SetFailed("Incorrect username or password!"); } } else { result.SetFailed("User not found!"); } } catch (Exception ex) { result.SetFailed(ex.Message); _logging.WriteErr(ex); } return(result); }
public ResultModel <object> Add(TaskDTO model) { ResultModel <object> result = new ResultModel <object>(); try { using (var transaction = _context.Database.BeginTransaction()) { try { var task = _mapper.Map <TaskDTO, Task>(model); _context.Entry(task).State = Microsoft.EntityFrameworkCore.EntityState.Added; _context.SaveChanges(); transaction.Commit(); result.SetSuccess("Data successfuly added"); } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.ToString()); } } } catch (Exception ex) { result.SetFailed(ex.Message); _logging.WriteErr(ex); } return(result); }