public async Task <ActionResult> Subscribe([FromForm] SubscribeModel model) { // this.ValidateCsrfToken(); if (!this.ModelState.IsValid) { return(BadRequest(new FormResponse { Message = string.Join(", ", this.ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage)), Result = this.ModelState.AsApiResult() })); } try { var emailGrain = this.grainClient.GetGrain <IEmailGrain>(0); await emailGrain.SendEmail(new Email { To = new List <string> { "*****@*****.**" }, MessageBody = $"<p>Keep me informed: {model.Email}</p>", Subject = $"Testing: subscriber request for {model.Email}", }); return(Ok(new FormResponse { Message = "Geregistreerd!", Result = ApiResult.AsSuccess() })); } catch (Exception e) { var result = new FormResponse { Result = ApiResult.AsException(e, includeExceptions: true), Message = "An Error occurred :-(" }; return(BadRequest(result)); } }
public async Task <IActionResult> CounterState(Guid id) { var grain = this.grainClient.GetGrain <ICounterGrain>(id); try { var state = (await grain.GetState()) ?? new CounterState(); return(Ok(state)); } catch (Exception e) { return(StatusCode(500, ApiResult.AsException(e, env.IsDevelopment()))); } }
public async Task <ActionResult> StopCounter() { var grain = this.grainClient.GetGrain <ICounterGrain>(this.sessionId); try { await grain.StopCounterTimer(); return(Ok()); } catch (Exception e) { return(StatusCode(500, ApiResult.AsException(e, env.IsDevelopment()))); } }
public static ApiModel AsException(AggregateException exception, bool includeExceptions = false) { return(new ApiModel(ApiResult.AsException(exception, includeExceptions))); }
public ApiModel(AggregateException e, bool includeExceptions) { this.Result = ApiResult.AsException(e, includeExceptions); }