public async Task <int> Post(AppointAdd model)
        {
            cmd.CommandText = "Appointment_Insert";
            SqlParameter param = new SqlParameter();

            param.ParameterName = "@Id";
            param.SqlDbType     = System.Data.SqlDbType.Int;
            param.Direction     = System.Data.ParameterDirection.Output;

            cmd.Parameters.Add(param);
            cmd.Parameters.AddWithValue("@UserId", model.UserId);
            cmd.Parameters.AddWithValue("@CustFName", model.CustFName);
            cmd.Parameters.AddWithValue("@CustLName", model.CustLName);
            cmd.Parameters.AddWithValue("@Street", model.Street);
            cmd.Parameters.AddWithValue("@City", model.City);
            cmd.Parameters.AddWithValue("@State", model.State);
            cmd.Parameters.AddWithValue("@Zip", model.Zip);
            cmd.Parameters.AddWithValue("@Email", model.Email);
            cmd.Parameters.AddWithValue("@Phone", model.Phone);
            cmd.Parameters.AddWithValue("@Appoint", model.Appoint);
            cmd.Parameters.AddWithValue("@ModifiedBy", model.ModifiedBy);
            cmd.Parameters.AddWithValue("@IsCnfrmed", model.IsCnfrmed       = false);
            cmd.Parameters.AddWithValue("@ReminderSent", model.ReminderSent = false);
            cmd.Parameters.AddWithValue("@CompName", model.CompName);
            cmd.Parameters.AddWithValue("@CompEmail", model.CompEmail);

            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
            int id = (int)cmd.Parameters["@Id"].Value;

            await SendEmail(model, id);

            return(id);
        }
        public async Task SendEmail(AppointAdd model, int id)
        {
            string EmailToken = Guid.NewGuid().ToString();

            //Create the send model and assign the data
            EmailDom sendModel = new EmailDom();

            sendModel.To   = new EmailAddress(model.Email, model.CustFName + " " + model.CustLName);
            sendModel.From = new EmailAddress(model.CompEmail, model.CompName);

            //assign links and change formats of zip and appoinment date and time to appear correctly in the email
            string link     = "http://localhost:51285/Account/CfrmAppoint/" + id;
            string editlink = "http://localhost:51285/Account/CustomerEdit/" + id;
            string zip      = (model.Zip).ToString();
            string appoint  = model.Appoint.ToString("MM/dd/yyyy hh:mm tt");

            sendModel.Subject = "Your Appointment with " + model.CompName;

            //build email and input correct information
            sendModel.HtmlTemplate = System.IO.File.ReadAllText("Models/EmailModels/ConfirmTemp.txt");
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{appoint}", appoint);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{firName}", model.CustFName);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{lasName}", model.CustLName);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{street}", model.Street);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{city}", model.City);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{state}", model.State);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{zip}", zip);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{email}", model.Email);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{phone}", model.Phone);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{{ConfirmUrl}}", link);
            sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{{EditUrl}}", editlink);

            //plain email for emails that cannot accept the HtmlTemplate
            sendModel.PlainTemplate = System.IO.File.ReadAllText("Models/EmailModels/ConfirmTempPlain.txt");
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{appoint}", appoint);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{firName}", model.CustFName);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{lasName}", model.CustLName);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{street}", model.Street);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{city}", model.City);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{state}", model.State);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{zip}", zip);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{email}", model.Email);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{phone}", model.Phone);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{{ConfirmUrl}}", link);
            sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{{EditUrl}}", editlink);

            //Send the email
            await SendEmail(sendModel);
        }
        public async Task <IActionResult> Post([FromBody] AppointAdd model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var user = await GetCurrentUser();

                model.UserId     = user.Id;
                model.ModifiedBy = user.UserName;
                DataResponse <int> resp = new DataResponse <int>();
                resp.Data = await _svc.Post(model);

                return(Ok(resp));
            }
            catch (Exception ex)
            {
                return(StatusCode(404, ex));
            }
        }