public async Task <IActionResult> Contact([FromForm] ContactModel model) { if (!this.ModelState.IsValid) // it should be possible to do a complete server render of form including the error... { return(BadRequest(this.ModelState.AsApiModel(model))); } try { var message = $"<h2>Contact request: {model.FirstName} {model.LastName}</h2><p>Name: {model.FirstName} {model.LastName}</p><p>Email: {model.Email}</p><p>Phone: {model.Phone}</p><p>Message: {model.Message}</p>"; var emailGrain = this.clusterClient.GetGrain <IEmailGrain>(0); await emailGrain.SendEmail( new Email { To = new List <string> { "*****@*****.**" }, MessageBody = message, Subject = $"Contact request: {model.Email}", }); return(Ok(ApiModel.AsSuccess <ContactModel>(model, "Message received"))); } catch (Exception e) { this.logger.LogError(e, $"An Exception of type {e.GetType().ToString()}: \"{e.Message}\" occurred in /subscribe.\r\n{e.StackTrace}"); return(StatusCode(StatusCodes.Status500InternalServerError, ApiModel.FromException(model, e, includeExceptions: this.env.IsDevelopment()))); } }
public async Task <ActionResult> Subscribe([FromForm] SubscribeModel model) { // this.ValidateCsrfToken(); if (!this.ModelState.IsValid) { return(BadRequest(this.ModelState.AsApiModel(model))); } try { var emailGrain = this.clusterClient.GetGrain <IEmailGrain>(0); await emailGrain.SendEmail( new Email { To = new List <string> { "*****@*****.**" }, MessageBody = $"<p>Keep me informed: {model.Email}</p>", Subject = $"Subscriber request: {model.Email}", }); return(Ok(ApiModel.AsSuccess(model, "Registered!"))); } catch (Exception e) { this.logger.LogError(e, $"An Exception of type {e.GetType().ToString()}: \"{e.Message}\" occurred in /subscribe.\r\n{e.StackTrace}"); return(StatusCode(StatusCodes.Status500InternalServerError, ApiModel.FromException(model, e, includeExceptions: this.env.IsDevelopment()))); } }