public IActionResult Post([FromBody] JobCardV3 jobcard) { if (jobcard == null) { return(BadRequest("JobCard is null.")); } _dataRepository.Add(jobcard); return(CreatedAtRoute("Get", new { Id = jobcard.JobCardID }, jobcard)); }
public IActionResult GetJobCardV3(Guid id) { JobCardV3 jobCard = _dataRepository.Get(id); if (jobCard == null) { return(NotFound("The JobCard record couldn't be found.")); } return(Ok(jobCard)); }
private async Task GetJobCardFromController(string ID) { //JobCard_TaskDescriptions_Context context = new JobCard_TaskDescriptions_Context(); //Guid idGuid = new Guid("00000000-0000-0000-0000-000000000012"); //List<JobCardV3> jobCard = context.JobCardsV3.Where(p => p.JobCardID == idGuid).ToList(); HttpClient client = new HttpClient(); string json = client.GetStringAsync(string.Format("http://localhost:5050/api/1/JobCardV3/{0}", ID)).ToString(); JobCardV3 jobCardTask = await Task.Run(() => JsonConvert.DeserializeObject <JobCardV3>(json)); }
private JobCardV3 GetJobCard(string jobCardID) { JobCardV3 jobCard = null; jobCardID = "00000000-0000-0000-0000-000000000012"; if (!string.IsNullOrEmpty(jobCardID)) { Task jobCardTask = GetJobCardFromController(jobCardID); } return(jobCard); }
public IActionResult Delete(Guid id) { JobCardV3 jobcard = _dataRepository.Get(id); if (jobcard == null) { return(NotFound("The JobCard record couldn't be found.")); } _dataRepository.Delete(jobcard); return(NoContent()); }
public async Task <IActionResult> SendMail([FromBody] Mail_Request request) { try { JobCardV3 jobCard = _dataRepository.Get(new Guid(request.JobCardID)); await mailService.SendEmailAsync(request, jobCard); return(Ok()); } catch (Exception ex) { throw; } }
public IActionResult Put(Guid id, [FromBody] JobCardV3 jobCard) { if (jobCard == null) { return(BadRequest("JobCard is Null")); } JobCardV3 jobCardToUpdate = _dataRepository.Get(id); if (jobCardToUpdate == null) { return(NotFound("The Jobcard record couldn't be found.")); } _dataRepository.Update(jobCardToUpdate, jobCard); return(NoContent()); }
private void ProcessDataIntoHtml(JobCardV3 jobCard) { // Get File and find and replace in files text string text = File.ReadAllText("C:\\temp\\Index.html"); // Business Name text = text.Replace("{Business Name}", jobCard.JobCardName); // Bill to string BillTo = string.Empty; if (jobCard.JTFA_Client != null && jobCard.JTFA_Client.Name != null) { BillTo = jobCard.JTFA_Client.Name; text = text.Replace("{Bill To}", BillTo); } // Make string vehicleMake = string.Empty; if (jobCard.Vehicle != null && jobCard.Vehicle.Make != null) { vehicleMake = jobCard.Vehicle.Make; text = text.Replace("{Vehicle Make}", vehicleMake); } // Make // VIN string VIN = string.Empty; if (jobCard.Vehicle != null && jobCard.Vehicle.VIN != null) { VIN = jobCard.Vehicle.VIN; text = text.Replace("{VIN}", VIN); } File.WriteAllText("C:\\temp\\Index.html", text); }
private void UnprocessDataFromHtml(JobCardV3 jobCard) { string text = File.ReadAllText("C:\\temp\\Index.html"); // Business Name text = text.Replace(jobCard.JobCardName, "{Business Name}"); // Invoice Number //text = text.Replace(jobCard., "{B Name}"); // Date // Bill to string BillTo = string.Empty; if (jobCard.JTFA_Client != null && jobCard.JTFA_Client.Name != null) { BillTo = jobCard.JTFA_Client.Name; text = text.Replace(BillTo, "{Bill To}"); } // Model // Make string vehicleMake = string.Empty; if (jobCard.Vehicle != null && jobCard.Vehicle.Make != null) { vehicleMake = jobCard.Vehicle.Make; text = text.Replace(vehicleMake, "{Vehicle Make}"); } // VIN string VIN = string.Empty; if (jobCard.Vehicle != null && jobCard.Vehicle.VIN != null) { VIN = jobCard.Vehicle.VIN; text = text.Replace(VIN, "{VIN}"); } File.WriteAllText("C:\\temp\\Index.html", text); }
public async Task SendEmailAsync(Mail_Request mail_Request, JobCardV3 jobCard) { MailMessage message = new MailMessage(); SmtpClient smtp = new SmtpClient(); message.From = new MailAddress(_mailSettings.Mail, _mailSettings.DisplayName); /*"toEmail": "*****@*****.**", * "subject": "astroids", * "jobCardID": null, * "body": "lekker astroids for light years!!!" */ mail_Request.Body = "lekker astroids for light years!!!"; mail_Request.Subject = "astroids"; /// TO EMAIL mail_Request.ToEmail = "*****@*****.**"; message.To.Add(new MailAddress(mail_Request.ToEmail)); message.Subject = mail_Request.Subject; // Input data from jobcard into html template ProcessDataIntoHtml(jobCard); // Convert HTML template into PDF CreatePDFFromHTMLTemplate(); // Unprocess the HTML for template ready phase UnprocessDataFromHtml(jobCard); // attach PDF Attachment att = new Attachment("SimpleConversionLocalHtml.pdf"); message.Attachments.Add(att); message.IsBodyHtml = false; message.Body = mail_Request.Body; smtp.Port = _mailSettings.Port; smtp.Host = _mailSettings.Host; smtp.EnableSsl = false; smtp.UseDefaultCredentials = false; _mailSettings.Mail = "*****@*****.**"; _mailSettings.Password = "******"; smtp.Credentials = new NetworkCredential(_mailSettings.Mail, _mailSettings.Password); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; //await smtp.SendMailAsync(message); // Build a PDF file and save it on disk from a job card //Converter.Convert(new Uri("https://www.google.com"), "SimpleConversion.pdf"); //ceTe.DynamicPDF.HtmlConverter.Converter.Convert(new Uri("https://www.google.com"), "SimpleConversion.pdf"); //ceTe.DynamicPDF.HtmlConverter.Converter.Convert(new Uri("HTML/index.html"), "SimpleConversionLocalHtml.pdf"); /* * if (mail_Request.Attachments != null) * { * foreach (var file in mail_Request.Attachments) * { * if (file.Length > 0) * { * using (var ms = new MemoryStream()) * { * file.CopyTo(ms); * var fileBytes = ms.ToArray(); * Attachment att = new Attachment(new MemoryStream(fileBytes), file.FileName); * message.Attachments.Add(att); * } * } * } * } */ }