Base solution for your next web application

Activities of "alinm"

I have a service in TemplateAppService :

[HttpPost]
public bool PostData([FromBody]ParametersDto _dto)
{
     //some code
     return true;
}

Angular Service(Typescript):

@Injectable()
export class DocumentService {

  private headers: any;
  private heroesUrl = 'http://172.18.0.81:62114/api/services/app/';  // URL to web api

  constructor(private http: Http, private authenticationService: AuthenticationService) {  
  }

  postDocData(ParametersDto data): Promise<any> {
    let headers = new Headers({ 'Content-Type': 'application/json', Authorization: 'Bearer ' + this.authenticationService.token });
    let options = new RequestOptions({ headers: headers });

    return this.http.post(this.heroesUrl + "TemplateDtl/PostData", JSON.stringify({dto:data}), options).toPromise()
      .then(response => response.json().result as any)
      .catch(this.handleError);
  }

  private handleError(error: any): Promise<any> {
    console.error('An error occurred', error); // for demo purposes only
    return Promise.reject(error.message || error);
  }
}

The post method does not work no matter what! I've tried passin a single parameter like this: [HttpPost]public bool PostData(int id)

I've tried changing request headers and added [FromBody] Attribute to parameters, but cannot get POST method to work. I also included [FromBody] & [HttpPost] Attributes in ITemplateAppService(interface) and TemplateAppService(class), still not working!

All the get methods (default) work fine. Methods other than GET behave strangely. What am I doing wrong? Am I missing something?

This code returns exception and logs an error in the browser for invalid Login credentials.

private async Task<AbpUserManager<Tenant, Role, User>.AbpLoginResult> GetLoginResultAsync(string usernameOrEmailAddress, string password, string tenancyName) { var loginResult = await _userManager.LoginAsync(usernameOrEmailAddress, password, tenancyName); switch (loginResult.Result) { case AbpLoginResultType.Success: return loginResult; default: throw CreateExceptionForFailedLoginAttempt(loginResult.Result, usernameOrEmailAddress, tenancyName); } }

In my case, i want to handle exception in javascript and show an error message

$('#LoginButton').click(function (e) { e.preventDefault(); abp.ui.setBusy( $('#LoginArea'), abp.ajax({ url: abp.appPath + 'Account/Login', type: 'POST', data: JSON.stringify({ tenancyName: $('#TenancyName').val(), usernameOrEmailAddress: $('#EmailAddressInput').val(), password: $('#PasswordInput').val(), rememberMe: $('#RememberMeInput').is(':checked'), returnUrlHash: $('#ReturnUrlHash').val() }) }) ); });

What can I do to achieve invalid credentials error message?

OK got it. i was missing System.Linq reference. Thanks!

what is the use of this class - [MyProject]AppServiceBase ??

In my PersonAppService(inherits ApplicationService) i can query using linq like: var user_info = _userManager.Users.Where(a => a.Id == this.AbpSession.UserId).Select(b => b);

But in UserAppService(created by template and inherits ProjectNameAppServiceBase) i cannot query using linq. It does not allow this: _userManager.Users.Where.....

what is the solution???

Showing 1 to 4 of 4 entries