public virtual async Task <Result <IEnumerable <T> > > GetAll() { try { if (!ModelState.IsValid) { return(Failed <IEnumerable <T> >()); } return(Succeeded(await _service.GetAllAsync())); } catch (Exception ex) { await _errorLogService.LogExceptionAsnc(ex); return(Failed <IEnumerable <T> >()); } }
public async Task <Result <AuthenticationResult> > Authenticate([FromBody] Users users) { try { var user = (await _usersService.Where(m => (m.Email.Trim().ToLower() == users.Email.Trim().ToLower() || m.UserName.Trim().ToLower() == users.Email.Trim().ToLower()) && m.Password == users.Password && m.UserTypeCode == users.UserTypeCode)).FirstOrDefault(); // If user not found if (user == null) { return(new Result <AuthenticationResult>(false, System.Net.HttpStatusCode.NotFound, Message.NotFound)); } // If user's email is not verified if (!user.IsEmailVerified) { return(new Result <AuthenticationResult>(false, System.Net.HttpStatusCode.Unauthorized, Message.VrifyEmail)); } // If user is inactive or deleted or blocked if (!user.IsActive || user.IsDeleted || user.IsBlocked) { return(new Result <AuthenticationResult>(false, System.Net.HttpStatusCode.Unauthorized, Message.UserBlocked)); } return(new Result <AuthenticationResult>(true, System.Net.HttpStatusCode.OK, new AuthenticationResult() { access_token = new JwtTokenBuilder().AddClaims(GetClaim(user.Email, user.UserTypeId, user.UserTypeCode)).Build().Value, expires_in = new TimeSpan(0, 5, 0) })); } catch (Exception ex) { await _errorLogService.LogExceptionAsnc(ex); return(new Result <AuthenticationResult>(false, System.Net.HttpStatusCode.InternalServerError, ex.Message)); } }