From dd330b0c1f1caee9e98314df1a045dbd12595a90 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Aug 2018 16:24:25 +0530 Subject: [PATCH] Email Sending Functionality --- 400-SOURCECODE/AIAHTML5.API/App_Start/WebApiConfig.cs | 48 ++++++++++++++++++++++++------------------------ 400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs | 16 +++++++++------- 400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs | 2 +- 400-SOURCECODE/AIAHTML5.API/Web.config | 13 +++++++++++-- 400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js | 37 +++++++++++++++++++++++++++++++++++++ 400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js | 27 +++++++++++++++++++++++++++ 400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 400-SOURCECODE/AIAHTML5.Web/term-number-wp1.js | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------- 400-SOURCECODE/AIAHTML5.Web/themes/default/css/bootstrap/3.3.6/main.css | 40 +++++++++++++++++++++++++++++++++++++++- 10 files changed, 390 insertions(+), 125 deletions(-) diff --git a/400-SOURCECODE/AIAHTML5.API/App_Start/WebApiConfig.cs b/400-SOURCECODE/AIAHTML5.API/App_Start/WebApiConfig.cs index 8c03032..fa90bbe 100644 --- a/400-SOURCECODE/AIAHTML5.API/App_Start/WebApiConfig.cs +++ b/400-SOURCECODE/AIAHTML5.API/App_Start/WebApiConfig.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web.Http; - -namespace AIAHTML5.API -{ - public static class WebApiConfig - { - public static void Register(HttpConfiguration config) - { - // Web API configuration and services - - // Web API routes - config.MapHttpAttributeRoutes(); - - config.Routes.MapHttpRoute( - name: "DefaultApi", - routeTemplate: "api/{controller}/{id}", - defaults: new { id = RouteParameter.Optional } - ); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web.Http; + +namespace AIAHTML5.API +{ + public static class WebApiConfig + { + public static void Register(HttpConfiguration config) + { + // Web API configuration and services + + // Web API routes + config.MapHttpAttributeRoutes(); + + config.Routes.MapHttpRoute( + name: "DefaultApi", + routeTemplate: "api/{controller}/{id}", + defaults: new { id = RouteParameter.Optional } + ); + } + } +} diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs index 9f619b9..56715b4 100644 --- a/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs @@ -217,7 +217,58 @@ namespace AIAHTML5.API.Controllers + [HttpPost] + public HttpResponseMessage Hi(int userId) + { + return Request.CreateResponse(HttpStatusCode.OK, userId.ToString()); + } + [Route("GetUserProfile/{userId}")] + [HttpGet] + public IHttpActionResult GetUserProfile(int userId) + { + //dbContext.Configuration.ProxyCreationEnabled = false; + try + { + return Ok("Hello"); + } + catch (Exception ex) + { + throw ex; + } + //return ToJson(dbContext.AIAUsers.Where(u => u.Id == userId).AsEnumerable()); + } + [Route("api/LabExercise/SendEmail")] + [HttpPost] + public HttpResponseMessage SendEmail([FromBody]JObject User) + { + ArrayList aar = new ArrayList(); + if (User["EmailTo"].ToString().ToLower().Contains(';')) + { + string[] words = User["EmailTo"].ToString().Split(';'); + foreach (string word in words) + { + Console.WriteLine(word); + aar.Add(word); + } + } + else + { + aar.Add(User["EmailTo"].ToString()); + } + if (User["ReportCheck"].ToString() == "true") + { + aar.Add(User["EmailAdd"].ToString()); + } + AIAHTML5.API.Models.UserUtility.SendEmail(User, aar, User["EmailAdd"].ToString(), "test", User["reportImage"].ToString()); + return Request.CreateResponse(HttpStatusCode.OK); + } + [Route("api/LabExercise/GetParameter")] + [HttpGet] + public IEnumerable GetParameter() + { + return new string[] { "val1", "val2" }; + } diff --git a/400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs b/400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs index 52f2547..1cc0e08 100644 --- a/400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs +++ b/400-SOURCECODE/AIAHTML5.API/Models/UserUtility.cs @@ -289,8 +289,8 @@ namespace AIAHTML5.API.Models lstToAddress.Add(email); } - emailMessage = "Unable to process request for "; - + //emailMessage = "Unable to process request for "; + emailMessage = " "; if (UserUtility.CheckIfPropertyExists(userInfo, "username") && !string.IsNullOrEmpty(userInfo["username"].ToString())) emailMessage += "username: " + userInfo["username"].ToString() + ""; if (UserUtility.CheckIfPropertyExists(userInfo, "password") && !string.IsNullOrEmpty(userInfo["password"].ToString())) @@ -309,18 +309,20 @@ namespace AIAHTML5.API.Models emailMessage = emailMessage.Replace("\n", "
"); - emailMessage += "

"; - + // emailMessage += "

"; + emailMessage += "" + emailMessage + ""; emailUtility.sHostName = Convert.ToString(ConfigurationManager.AppSettings["HostAddress"]); emailUtility.sFromAddress = senderEmailId; emailUtility.bIsBodyHtml = true; - emailUtility.bEnableSsl = false; + // emailUtility.bEnableSsl = false; + emailUtility.bEnableSsl = true; emailUtility.sSubject = mailSubject; emailUtility.sBodyText = emailMessage; - emailUtility.iPort = 25; + //emailUtility.iPort = 25; + emailUtility.iPort = 587; emailUtility.sToAddresses = lstToAddress; emailUtility.sBccAddresses = lstBccAddress; - + emailUtility.sUserName = senderEmailId; emailUtility.SendSmtpEmail(); return true; } diff --git a/400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs b/400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs index a2152f0..960420c 100644 --- a/400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs +++ b/400-SOURCECODE/AIAHTML5.API/Utility/EmailUtility.cs @@ -39,7 +39,7 @@ namespace AIAHTML5.API.Utility System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(mm.From.ToString(), ConfigurationManager.AppSettings["SenderPassword"]); smtp.Credentials = NetworkCred; smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]); - + smtp.EnableSsl = false; smtp.Send(mm); } catch (Exception e) diff --git a/400-SOURCECODE/AIAHTML5.API/Web.config b/400-SOURCECODE/AIAHTML5.API/Web.config index ee162e6..dd98f5d 100644 --- a/400-SOURCECODE/AIAHTML5.API/Web.config +++ b/400-SOURCECODE/AIAHTML5.API/Web.config @@ -32,13 +32,22 @@ - + + + + + + + + + + diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js index c3736a0..89e013b 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js @@ -1289,7 +1289,44 @@ function ($scope, $rootScope, pages, log, $http, $timeout, DataService, $filter, } + $scope.SendLabEXMailToUser = function (User) { + console.log(User); + html2canvas($("#submitResultHtml"), { + onrendered: function (canvas) { + var dataURL = canvas.toDataURL("image/jpeg"); + var imageToPrint = new Image(); + imageToPrint.src = dataURL; + console.log(imageToPrint.src); + $scope.reportImage = imageToPrint.src; + } + }); + debugger; + LabExerciseService.LabExerciseReport(User, $scope.reportImage).then( + function (result) { + console.log(result); + }, + function (error) { + console.log(error.statusText); + } + ) + + + } + $rootScope.closeLabExEmailModel = function () { + document.getElementById("LabExerciseForm").reset(); + $scope.LabExForm.$setPristine(); + $scope.LabExForm.$setUntouched(); + document.body.style.overflow = "scroll"; + document.getElementById('labExModalbackground').style.display = "none"; + document.getElementById('labExModalID').style.display = "none"; + } + $rootScope.sendMail = function () { + window.scrollTo(0, 0); + document.body.style.overflow = "hidden"; + document.getElementById('labExModalbackground').style.display = "block"; + document.getElementById('labExModalID').style.display = "block"; + } }] diff --git a/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js b/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js index 71e274f..0935b33 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js @@ -49,5 +49,32 @@ }); return deferred.promise; }, + + // code of email report + LabExerciseReport: function (User, reportImage) { + User.reportImage = reportImage; + var deferred = $q.defer(); + debugger; + // var jsonData = { 'EmailTo': User.EmailTo, 'EmailAdd': User.EmailAdd }; + $http.post('http://192.168.90.19:91/API/api/LabExercise/SendEmail', JSON.stringify(User), { + + headers: { + 'Content-Type': 'application/json' + }, + // data: { Users: JSON.stringify(jsonData) } + }) + + .success(function (data, status, headers, config) { + debugger; + console.log('success') + deferred.resolve(data); + }).error(function (data, status, headers, config) { + debugger; + console.log('error') + deferred.reject(data); + }); + return deferred.promise; + } + } }) \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html b/400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html index 06cfb89..262df82 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html +++ b/400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html @@ -11,6 +11,107 @@
+ + + + + + + +
+ +
+ +
+ + + + + + + + + +

LAB Ex ...

@@ -135,7 +236,7 @@