public async Task <ActionResult> ChangeStatus(FormCollection form, ChangeStatusViewModel model) { try { orderProvider.SetStatusOrder(model.OrderId, model.NewStatusId, model.Notes, model.SendMail); if (model.SendMail) { var order = orderProvider.GetOrder(model.OrderId); var orderStatus = orderStatusProvider.GetOrderStatus(model.NewStatusId); var viewModel = orderProvider.GetOrderMail(order); if (orderStatus != null) { var config = new TemplateServiceConfiguration(); using (var service = RazorEngineService.Create(config)) { var body = service.RunCompile( orderStatus.EmailTemplate, "OrderMail", typeof(OrderMailViewModel), new { viewModel }); await orderProvider.NotifyOrderStatusUpdate( ConfigurationInstance[ConfigurationKeys.SmtpServer], Convert.ToInt32(ConfigurationInstance[ConfigurationKeys.SmtpPort]), Convert.ToBoolean(ConfigurationInstance[ConfigurationKeys.SmtpSsl]), !Convert.ToBoolean(ConfigurationInstance[ConfigurationKeys.SmtpAuthentication]), ConfigurationInstance[ConfigurationKeys.SmtpUserName], ConfigurationInstance[ConfigurationKeys.SmtpPassword], ConfigurationInstance[ConfigurationKeys.SystemSenderName], ConfigurationInstance[ConfigurationKeys.SystemSenderAddress], viewModel.CustomerMail, body); } } } } catch (Exception ex) { Response.StatusCode = 406; Response.Write(ex.Message); return(null); } return(Json(model)); }