public static AccountSource ToModel(this AccountSourceRequest sourceContract) { return(new AccountSource { Description = sourceContract.Description, Token = sourceContract.Token, RequiresPassword = sourceContract.RequiresPassword.Value, AutoRegister = sourceContract.AutoRegister.Value }); }
// todo refactor accountSource request into AccountSourceUpdateRequest (which requires the Id) and AccountSourceCreateRequest (which has no required Id field) - and remove the Id param from the definition below public async Task <IActionResult> Update([FromRoute] int id, [FromBody] AccountSourceRequest accountSource) { if ((await _authorizationService.AuthorizeAsync(User, id, HttpContext.ScopeItems(ClaimScope.Global))).Succeeded) { var accountSourceModel = accountSource.ToModel(); accountSourceModel.Id = id; _accountSourceCoreController.Update(accountSourceModel); return(Ok()); } return(Forbid()); }
public async Task <IActionResult> Create([FromBody] AccountSourceRequest newAccountSource) { if ((await _authorizationService.AuthorizeAsync(User, Platform.AllId, HttpContext.ScopeItems(ClaimScope.Global))).Succeeded) { var accountSource = newAccountSource.ToModel(); _accountSourceCoreController.Create(accountSource); var accountSourceContract = accountSource.ToContract(); return(new ObjectResult(accountSourceContract)); } return(Forbid()); }