Exemple #1
0
        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));
            }
        }
Exemple #2
0
        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())));
            }
        }
Exemple #3
0
        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())));
            }
        }
Exemple #4
0
 public static ApiModel AsException(AggregateException exception, bool includeExceptions = false)
 {
     return(new ApiModel(ApiResult.AsException(exception, includeExceptions)));
 }
Exemple #5
0
 public ApiModel(AggregateException e, bool includeExceptions)
 {
     this.Result = ApiResult.AsException(e, includeExceptions);
 }