public async Task <ResponseStructure> AdminLogin(UserModel um) { try { var getAll = (List <UserModel>)(await GetAll()).Data; var exists = getAll.FirstOrDefault(x => x.U_Email == um.U_Email); bool truepwd = false; if (exists == null || !CryptoJsService.verifyPassword(exists.U_Password, um.U_Password)) { return(ResponseModel.Error("Sorry,we couldn't find an account with that username and password.")); } if (exists.U_Status == 2) { return(ResponseModel.Error("Your account has been suspened.")); } if (um.U_Role == 1) { var perms = _context.Permissions.Where(x => x.Perm_Uid == exists.U_Id).ToList(); foreach (var perm in perms) { um.Permissions.Add(perm.Perm_Urlid); } } var token = TokenService.GenerateToken(exists.U_Id, exists.U_Name + " " + exists.U_Family, exists.U_Email); um.Token = token; return(ResponseModel.Success(data: um)); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }
public async Task <ResponseStructure> InertAdmin(UserModel um) { try { var getAll = (List <UserModel>)(await GetAll()).Data; bool exists = getAll.Count(x => x.U_Phone == um.U_Email && x.U_Role == um.U_Role) > 0; if (exists) { return(ResponseModel.Error("This email already exists.")); } um.Created_At = DateTime.Now; um.Updated_At = DateTime.Now; um.U_Status = 1; um.U_Password = CryptoJsService.HashPassword(um.U_Password); await this._context.Users.AddAsync(entity : um); await this.CommitAllChanges(); if (um.U_Role == 1) { foreach (var perm in um.Permissions) { this._context.Permissions.Add(new PermissionModel() { Perm_Uid = um.U_Id, Perm_Urlid = perm }); } await this.CommitAllChanges(); } return(ResponseModel.Success("Registration completed Successfully!")); } catch (Exception ex) { return(ResponseModel.ServerInternalError(data: ex)); } }