Exemple #1
0
        public void InvestigationEmails()
        {
            IQueryable <InvestigationEmails> InvestigationEmailsInvestigationEmails = Enumerable.Empty <InvestigationEmails>().AsQueryable();
            InvestigationEmails ct = new InvestigationEmails {
                InvestigationEmailID = 1, EmailBody = "Test InvestigationEmails"
            };

            Mock <IInvestigationEmailsRepository> InvestigationEmailsService = new Mock <IInvestigationEmailsRepository>();

            object obj = new object();

            try
            {
                InvestigationEmailsService.Setup(x => x.GetAll()).Returns(InvestigationEmailsInvestigationEmails);
                InvestigationEmailsService.Setup(x => x.Get(It.IsAny <int>())).Returns(ct);
                InvestigationEmailsService.Setup(x => x.Add(It.IsAny <InvestigationEmails>())).Returns(ct);
                InvestigationEmailsService.Setup(x => x.Delete(It.IsAny <InvestigationEmails>())).Verifiable();
                InvestigationEmailsService.Setup(x => x.Update(It.IsAny <InvestigationEmails>(), It.IsAny <object>())).Returns(ct);

                var InvestigationEmailsObject = InvestigationEmailsService.Object;
                var p1 = InvestigationEmailsObject.GetAll();
                var p2 = InvestigationEmailsObject.Get(1);
                var p3 = InvestigationEmailsObject.Update(ct, obj);
                var p4 = InvestigationEmailsObject.Add(ct);
                InvestigationEmailsObject.Delete(ct);

                Assert.IsAssignableFrom <IQueryable <InvestigationEmails> >(p1);
                Assert.IsAssignableFrom <InvestigationEmails>(p2);
                Assert.Equal("Test InvestigationEmails", p2.EmailBody);
                Assert.Equal("Test InvestigationEmails", p3.EmailBody);

                InvestigationEmailsService.VerifyAll();

                InvestigationEmailsObject.Dispose();
            }
            finally
            {
                InvestigationEmailsService = null;
            }
        }
        public IActionResult Update([FromBody] InvestigationEmails editentry)
        {
            var result = _repository.Update(editentry, editentry.InvestigationEmailID);

            return(Helper.CheckResult(result));
        }
        public IActionResult Create([FromBody] InvestigationEmails newentry)
        {
            var result = _repository.Add(newentry);

            return(Helper.CheckResult(result));
        }
Exemple #4
0
        public object SendInvestigationEmail(InvestiationEmailRequest emailrequest, IConfiguration configuration)
        {
            if (Helper.ValidEmail(emailrequest.RecipientEmail) == false)
            {
                return(null);
            }
            if (emailrequest.Subject.Trim() == "" || emailrequest.Message.Trim() == "" ||
                emailrequest.AppUserID == 0 || emailrequest.IndexFromWorkTable == 0)
            {
                return(null);
            }

            var fromEditorialUser = _context.AppUser.Where(x => x.AppUserID == emailrequest.AppUserID).FirstOrDefault();

            if (fromEditorialUser == null)
            {
                return(null);
            }
            var SentFrom = fromEditorialUser.Email;

            // Investigation Entry
            var thisInvestigation = _context.Investigation
                                    .Where(x => x.InvestigationID == emailrequest.IndexFromWorkTable).FirstOrDefault();

            if (thisInvestigation == null)
            {
                return(null);
            }

            var SMTPServer              = configuration.GetSection("EmailSettings:SMTPServer").Value;
            var SMTPPort                = configuration.GetSection("EmailSettings:SMTPPort").Value;
            var InvestigationToEmail    = configuration.GetSection("EmailSettings:ToEmail").Value;
            var InvestigationCCEmail    = configuration.GetSection("EmailSettings:CCEmail").Value;
            var InvestigationBCCEmail   = configuration.GetSection("EmailSettings:BCCEmail").Value;
            var DevEmailAddress         = configuration.GetSection("EmailSettings:DevEmailAddress").Value;
            var StatusOrErrorMessage    = configuration.GetSection("EmailSettings:StatusOrErrorMessage").Value;
            var ResearchersEmailAddress = configuration.GetSection("EmailSettings:ResearchersEmailAddress").Value;
            var InvestigationEmailSendFromEmailAddress = configuration.GetSection("EmailSettings:SendFromEmailAddress").Value;

            var IsDevelopment = configuration.GetSection("EmailSettings:Development").Value;

            // TO (recipients)
            var SentTo = emailrequest.RecipientEmail;

            if (InvestigationToEmail != "")
            {
                SentTo += ";" + InvestigationToEmail;
            }
            if (InvestigationCCEmail != "")
            {
                SentTo += ";" + InvestigationCCEmail;
            }
            if (InvestigationBCCEmail != "")
            {
                SentTo += ";" + InvestigationBCCEmail;
            }

            var InvestigationEmailEntry = new InvestigationEmails();

            var SentDateUTC    = DateTime.UtcNow;
            var DateCreatedUTC = DateTime.UtcNow;
            var LastUpdatedUTC = DateTime.UtcNow;

            var CreatedBy = emailrequest.AppUserID.ToString();
            var UpdatedBy = emailrequest.AppUserID.ToString();

            var Subject   = emailrequest.Subject;
            var EmailBody = emailrequest.Message;

            InvestigationEmailEntry.InvestigationID      = emailrequest.IndexFromWorkTable;
            InvestigationEmailEntry.AppUserID            = emailrequest.AppUserID;
            InvestigationEmailEntry.SentTo               = SentTo;
            InvestigationEmailEntry.SentFrom             = SentFrom;
            InvestigationEmailEntry.Subject              = Subject;
            InvestigationEmailEntry.EmailBody            = EmailBody;
            InvestigationEmailEntry.StatusOrErrorMessage = StatusOrErrorMessage;
            InvestigationEmailEntry.SentDateUTC          = SentDateUTC;
            InvestigationEmailEntry.CreatedBy            = CreatedBy;
            InvestigationEmailEntry.DateCreatedUTC       = DateCreatedUTC;
            InvestigationEmailEntry.UpdatedBy            = UpdatedBy;
            InvestigationEmailEntry.LastUpdatedUTC       = LastUpdatedUTC;

            _context.InvestigationEmails.Add(InvestigationEmailEntry);

            // Log Activity
            var thisActivity = new InvestigationActivity
            {
                InvestigationID = thisInvestigation.InvestigationID,
                ActivityTypeID  = 8, //Email Sent Activity Type
                AppUserID       = fromEditorialUser.AppUserID,
                FromValue       = "",
                ToValue         = "Sent Email",
                CreatedBy       = CreatedBy,
                DateCreatedUTC  = DateCreatedUTC,
                UpdatedBy       = UpdatedBy,
                LastUpdatedUTC  = LastUpdatedUTC
            };

            _context.SaveChanges();

            _context.InvestigationActivity.Add(thisActivity);

            // dummy, comment/delete when ready
            SentFrom = "*****@*****.**";
            SentTo   = "*****@*****.**";

            Helper.SendMail(SMTPServer, SentFrom, SentTo, "", "", Subject, EmailBody);

            return(EmailBody);
        }
Exemple #5
0
        public IActionResult SendInvestigationEmail([FromBody] InvestiationEmailRequest emailreq)
        {
            if (Common.IsValidEmail(emailreq.RecipientEmail) != true)
            {
                return(BadRequest("Invalid Email"));
            }

            if (emailreq.Subject.Trim() == "" || emailreq.Message.Trim() == "" ||
                emailreq.AppUserID == 0 || emailreq.IndexFromWorkTable == 0)
            {
                return(BadRequest("Invalid Request, Subject, Body or User cannot be empty "));
            }

            // From User
            var thisUser = _context.AppUser
                           .Where(x => x.AppUserID == emailreq.AppUserID).FirstOrDefault();

            if (thisUser == null)
            {
                return(BadRequest("User does not Exist "));
            }
            var SentFrom = thisUser.Email;

            // Investigation Entry
            var thisInvestigation = _context.Investigation
                                    .Where(x => x.InvestigationID == emailreq.IndexFromWorkTable).FirstOrDefault();

            if (thisInvestigation == null)
            {
                return(BadRequest("Investigation Record does not Exist "));
            }

            var SMTPServer              = _configuration.GetSection("EmailSettings:SMTPServer").Value;
            var SMTPPort                = _configuration.GetSection("EmailSettings:SMTPPort").Value;
            var InvestigationToEmail    = _configuration.GetSection("EmailSettings:InvestigationToEmail").Value;
            var InvestigationCCEmail    = _configuration.GetSection("EmailSettings:InvestigationCCEmail").Value;
            var InvestigationBCCEmail   = _configuration.GetSection("EmailSettings:InvestigationBCCEmail").Value;
            var DevEmailAddress         = _configuration.GetSection("EmailSettings:DevEmailAddress").Value;
            var StatusOrErrorMessage    = _configuration.GetSection("EmailSettings:StatusOrErrorMessage").Value;
            var ResearchersEmailAddress = _configuration.GetSection("EmailSettings:ResearchersEmailAddress").Value;
            var InvestigationEmailSendFromEmailAddress = _configuration.GetSection("EmailSettings:InvestigationEmailSendFromEmailAddress").Value;

            var IsDevelopment = _configuration.GetSection("EmailSettings:Development").Value;

            // TO (recipients)
            var SentTo = emailreq.RecipientEmail;

            if (InvestigationToEmail != "")
            {
                SentTo += ";" + InvestigationToEmail;
            }
            if (InvestigationCCEmail != "")
            {
                SentTo += ";" + InvestigationCCEmail;
            }
            if (InvestigationBCCEmail != "")
            {
                SentTo += ";" + InvestigationBCCEmail;
            }

            var InvestigationEmailEntry = new InvestigationEmails();

            var SentDateUTC    = DateTime.UtcNow;
            var DateCreatedUTC = DateTime.UtcNow;
            var LastUpdatedUTC = DateTime.UtcNow;

            var CreatedBy = emailreq.AppUserID.ToString();
            var UpdatedBy = emailreq.AppUserID.ToString();

            var Subject   = emailreq.Subject;
            var EmailBody = emailreq.Message;

            // Log Entry in email table
            InvestigationEmailEntry.InvestigationID      = emailreq.IndexFromWorkTable;
            InvestigationEmailEntry.AppUserID            = emailreq.AppUserID;
            InvestigationEmailEntry.SentTo               = SentTo;
            InvestigationEmailEntry.SentFrom             = SentFrom;
            InvestigationEmailEntry.Subject              = Subject;
            InvestigationEmailEntry.EmailBody            = EmailBody;
            InvestigationEmailEntry.StatusOrErrorMessage = StatusOrErrorMessage;
            InvestigationEmailEntry.SentDateUTC          = SentDateUTC;
            InvestigationEmailEntry.CreatedBy            = CreatedBy;
            InvestigationEmailEntry.DateCreatedUTC       = DateCreatedUTC;
            InvestigationEmailEntry.UpdatedBy            = UpdatedBy;
            InvestigationEmailEntry.LastUpdatedUTC       = LastUpdatedUTC;

            _context.InvestigationEmails.Add(InvestigationEmailEntry);
            // Log Activity
            var thisActivity = new InvestigationActivity();

            thisActivity.InvestigationID = thisInvestigation.InvestigationID;
            thisActivity.ActivityTypeID  = 8; //Email Sent Activity Type
            thisActivity.AppUserID       = thisUser.AppUserID;
            thisActivity.FromValue       = "";
            thisActivity.ToValue         = "Sent Email";
            thisActivity.CreatedBy       = CreatedBy;
            thisActivity.DateCreatedUTC  = DateCreatedUTC;
            thisActivity.UpdatedBy       = UpdatedBy;
            thisActivity.LastUpdatedUTC  = LastUpdatedUTC;

            _context.InvestigationActivity.Add(thisActivity);

            ReturnData retValue;

            retValue = _context.SaveData();

            if (retValue.Message != "Success")
            {
                return(Json(retValue));
            }

            // remove after
            SentFrom = "*****@*****.**";
            SentTo   = "*****@*****.**";

            var emailSent = Common.SendMail(SMTPServer, SentFrom, SentTo, "", "", Subject, EmailBody, _logger);

            if (emailSent != "Success")
            {
                return(BadRequest(emailSent));
            }

            return(Ok());
        }