/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='model'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> Post1Async(this IStsApi operations, TeamUserRequest model = default(TeamUserRequest), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.Post1WithHttpMessagesAsync(model, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public async Task <IActionResult> Post([FromBody] TeamUserRequest model) { TeamUser newRecord = null; if (ModelState.IsValid) { InitUserCredentials(); // check for user var user = await _usersService.Get(model.UserGuid); if (user == null || user.CompanyGuid != CompanyGuid) { return(BadRequest()); } var team = await _teamService.Get(model.TeamGuid); if (team == null || team.CompanyGuid != CompanyGuid) { return(BadRequest()); } newRecord = new TeamUser { Guid = Guid.NewGuid(), CompanyGuid = CompanyGuid, CreationTime = DateTime.UtcNow, CreationUserGuid = UserGuid, TeamGuid = team.Guid, UserGuid = model.UserGuid, }; newRecord = _mapper.Map(model, newRecord); try { await _teamUserService.Save(newRecord); } catch (Exception e) { Log.Error(e.StackTrace); throw; } } return(CreatedAtAction(nameof(Post), _mapper.Map(newRecord, new TeamUserResponse()))); }
public async Task <IActionResult> Put([FromBody] TeamUserRequest model, Guid guid) { if (ModelState.IsValid) { if (guid == Guid.Empty) { return(new BadRequestResult()); } TeamUser record = await _teamUserService.Get(guid); if (record == null) { return(new NoContentResult()); } InitUserCredentials(); if (record.UserGuid != UserGuid) { return(new UnauthorizedResult()); } var mapped = _mapper.Map(model, record); mapped.LastUpdateTime = DateTime.Now; mapped.LastUpdateUserGuid = UserGuid; try { await _teamUserService.Save(mapped); } catch (Exception e) { Log.Error(e.StackTrace); throw; } } return(new OkResult()); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='model'> /// </param> public static object Post1(this IStsApi operations, TeamUserRequest model = default(TeamUserRequest)) { return(operations.Post1Async(model).GetAwaiter().GetResult()); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='guid'> /// </param> /// <param name='model'> /// </param> public static object Put1(this IStsApi operations, System.Guid guid, TeamUserRequest model = default(TeamUserRequest)) { return(operations.Put1Async(guid, model).GetAwaiter().GetResult()); }