public InvestigationActivity AddInvestigationActivity(InvestigationDataSave investigationactivity) { var investigationEntry = investigationactivity.Investigation; var targetinvestigationEntry = _context.Investigation.FirstOrDefault(t => t.InvestigationID == investigationEntry.InvestigationID); if (targetinvestigationEntry == null) { return(null); } int ActivityTypeValue = 0; if (investigationEntry.PriorityTypeID != targetinvestigationEntry.PriorityTypeID) // Priority change { ActivityTypeValue = 5; // Priority type, table [ActivityType] } else if (investigationEntry.CountryID != targetinvestigationEntry.CountryID) // Country change { ActivityTypeValue = 3; // Country Type, table [ActivityType] } else if (investigationEntry.InvestigationStatusID != targetinvestigationEntry.InvestigationStatusID) // Status change { ActivityTypeValue = 2; // Status Type, table [ActivityType] } else if (investigationEntry.FunctionTypeID != targetinvestigationEntry.FunctionTypeID) // Category change { ActivityTypeValue = 7; // Category Type, table [ActivityType] } else if (investigationEntry.InvestigationDispositionsID != targetinvestigationEntry.InvestigationDispositionsID) // Disposition change { ActivityTypeValue = 6; // Disposition Type, table [ActivityType] } else { return(null); } InvestigationActivity newActivity = new InvestigationActivity { AppUserID = Convert.ToInt32(investigationEntry.UpdatedBy), CreatedBy = investigationEntry.UpdatedBy, DateCreatedUTC = DateTime.UtcNow, UpdatedBy = investigationEntry.UpdatedBy, LastUpdatedUTC = DateTime.UtcNow, InvestigationID = targetinvestigationEntry.InvestigationID, FromValue = investigationEntry.PriorityTypeID.ToString(), ToValue = targetinvestigationEntry.PriorityTypeID.ToString(), ActivityTypeID = ActivityTypeValue }; _context.InvestigationActivity.Add(newActivity); _context.SaveChanges(); return(newActivity); }
public IActionResult Create([FromBody] InvestigationActivity newmodel) { if (ModelState.IsValid) { _context.InvestigationActivity.Add(newmodel); ReturnData ret; ret = _context.SaveData(); if (ret.Message == "Success") { return(CreatedAtRoute("GetInvestigationActivity", new { id = newmodel.InvestigationActivityID }, newmodel)); } return(NotFound(ret)); } else { return(BadRequest()); } }
public IActionResult UpdateEntry([FromBody] InvestigationActivity objupd) { var targetObject = _context.InvestigationActivity.FirstOrDefault(t => t.InvestigationActivityID == objupd.InvestigationActivityID); if (targetObject == null) { return(NotFound()); } _context.Entry(targetObject).CurrentValues.SetValues(objupd); ReturnData ret; ret = _context.SaveData(); if (ret.Message == "Success") { return(Ok()); } return(NotFound(ret)); }
public void InvestigationActivity() { IQueryable <InvestigationActivity> InvestigationActivityInvestigationActivity = Enumerable.Empty <InvestigationActivity>().AsQueryable(); InvestigationActivity ct = new InvestigationActivity { InvestigationActivityID = 1, CreatedBy = "Test InvestigationActivity" }; Mock <IInvestigationActivityRepository> InvestigationActivityService = new Mock <IInvestigationActivityRepository>(); object obj = new object(); try { InvestigationActivityService.Setup(x => x.GetAll()).Returns(InvestigationActivityInvestigationActivity); InvestigationActivityService.Setup(x => x.Get(It.IsAny <int>())).Returns(ct); InvestigationActivityService.Setup(x => x.Add(It.IsAny <InvestigationActivity>())).Returns(ct); InvestigationActivityService.Setup(x => x.Delete(It.IsAny <InvestigationActivity>())).Verifiable(); InvestigationActivityService.Setup(x => x.Update(It.IsAny <InvestigationActivity>(), It.IsAny <object>())).Returns(ct); var InvestigationActivityObject = InvestigationActivityService.Object; var p1 = InvestigationActivityObject.GetAll(); var p2 = InvestigationActivityObject.Get(1); var p3 = InvestigationActivityObject.Update(ct, obj); var p4 = InvestigationActivityObject.Add(ct); InvestigationActivityObject.Delete(ct); Assert.IsAssignableFrom <IQueryable <InvestigationActivity> >(p1); Assert.IsAssignableFrom <InvestigationActivity>(p2); Assert.Equal("Test InvestigationActivity", p2.CreatedBy); Assert.Equal("Test InvestigationActivity", p3.CreatedBy); InvestigationActivityService.VerifyAll(); InvestigationActivityObject.Dispose(); } finally { InvestigationActivityService = null; } }
public void InvestigationActivity() { using (var context = new AppDbContext(options, null)) { var controller = new InvestigationActivityController(context); // Get all var result = controller.Get(); // Assert var okResult = Assert.IsAssignableFrom <IEnumerable <InvestigationActivity> >(result); var pgcount = okResult.ToList().Count; Assert.Equal(2, pgcount); // Get by ID var result1 = controller.Get(1); var okResult1 = Assert.IsAssignableFrom <InvestigationActivity>(result1); Assert.Equal("InvestigationActivity 1", result1.FromValue); // test update var pg1 = new InvestigationActivity { InvestigationActivityID = 1, FromValue = "InvestigationActivity 1 upd" }; controller.UpdateEntry(pg1); var result3 = controller.Get(1); Assert.NotEqual("InvestigationActivity 1", result3.FromValue); Assert.Equal("InvestigationActivity 1 upd", result3.FromValue); // test delete var result4 = controller.Get(2); Assert.Equal("InvestigationActivity 2", result4.FromValue); IActionResult result5 = controller.Delete(2); var viewResult = Assert.IsType <OkResult>(result5); var result6 = controller.Get(2); Assert.Null(result6); } }
internal void PopulateData() { using (var context = new AppDbContext(options, null)) { if (context.ActivityType.Count() < 1) { var p1 = new ActivityType { ActivityTypeID = 1, ActivityTypeName = "activity type 1", }; var p2 = new ActivityType { ActivityTypeID = 2, ActivityTypeName = "activity type 2", }; context.ActivityType.Add(p1); context.ActivityType.Add(p2); context.SaveChanges(); } if (context.InvestigationNote.Count() < 1) { var p1 = new InvestigationNote { InvestigationNoteID = 1, NoteText = "InvestigationNote 1", }; var p2 = new InvestigationNote { InvestigationNoteID = 2, NoteText = "InvestigationNote 2", }; context.InvestigationNote.Add(p1); context.InvestigationNote.Add(p2); context.SaveChanges(); } if (context.InvestigationStatus.Count() < 1) { var p1 = new InvestigationStatus { InvestigationStatusID = 1, InvestigationStatusDescription = "InvestigationStatus 1", }; var p2 = new InvestigationStatus { InvestigationStatusID = 2, InvestigationStatusDescription = "InvestigationStatus 2", }; context.InvestigationStatus.Add(p1); context.InvestigationStatus.Add(p2); context.SaveChanges(); } if (context.InvestigationActivity.Count() < 1) { var p1 = new InvestigationActivity { InvestigationActivityID = 1, FromValue = "InvestigationActivity 1", }; var p2 = new InvestigationActivity { InvestigationActivityID = 2, FromValue = "InvestigationActivity 2", }; context.InvestigationActivity.Add(p1); context.InvestigationActivity.Add(p2); context.SaveChanges(); } } }
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); }
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()); }
public IActionResult AddActivity([FromBody] InvestigationDataSave objupdobj) { var objupd = objupdobj.Investigation; var targetObject = _context.Investigation.FirstOrDefault(t => t.InvestigationID == objupd.InvestigationID); if (targetObject == null) { return(NotFound()); } List <InvestigationActivity> Activities = new List <InvestigationActivity>(); bool hasChanges = false; if (objupd.PriorityTypeID != targetObject.PriorityTypeID) // Priority change { var newActivity = new InvestigationActivity(); newActivity.AppUserID = Convert.ToInt32(objupd.UpdatedBy); newActivity.CreatedBy = objupd.UpdatedBy; newActivity.DateCreatedUTC = DateTime.UtcNow; newActivity.UpdatedBy = objupd.UpdatedBy; newActivity.LastUpdatedUTC = DateTime.UtcNow; newActivity.InvestigationID = targetObject.InvestigationID; newActivity.FromValue = objupd.PriorityTypeID.ToString(); newActivity.ToValue = targetObject.PriorityTypeID.ToString(); newActivity.ActivityTypeID = 5; // Priority Type //Activities.Add(newActivity); _context.InvestigationActivity.Add(newActivity); hasChanges = true; } if (objupd.CountryID != targetObject.CountryID) // Country change { var newActivity = new InvestigationActivity(); newActivity.AppUserID = Convert.ToInt32(objupd.UpdatedBy); newActivity.CreatedBy = objupd.UpdatedBy; newActivity.DateCreatedUTC = DateTime.UtcNow; newActivity.UpdatedBy = objupd.UpdatedBy; newActivity.LastUpdatedUTC = DateTime.UtcNow; newActivity.InvestigationID = targetObject.InvestigationID; newActivity.FromValue = objupd.PriorityTypeID.ToString(); newActivity.ToValue = targetObject.PriorityTypeID.ToString(); newActivity.ActivityTypeID = 3; // Country Type //Activities.Add(newActivity); _context.InvestigationActivity.Add(newActivity); hasChanges = true; } if (objupd.InvestigationStatusID != targetObject.InvestigationStatusID) // Status change { var newActivity = new InvestigationActivity(); newActivity.AppUserID = Convert.ToInt32(objupd.UpdatedBy); newActivity.CreatedBy = objupd.UpdatedBy; newActivity.DateCreatedUTC = DateTime.UtcNow; newActivity.UpdatedBy = objupd.UpdatedBy; newActivity.LastUpdatedUTC = DateTime.UtcNow; newActivity.InvestigationID = targetObject.InvestigationID; newActivity.FromValue = objupd.PriorityTypeID.ToString(); newActivity.ToValue = targetObject.PriorityTypeID.ToString(); newActivity.ActivityTypeID = 2; // Status Type //Activities.Add(newActivity); _context.InvestigationActivity.Add(newActivity); hasChanges = true; } if (objupd.FunctionTypeID != targetObject.FunctionTypeID) // Category change { var newActivity = new InvestigationActivity(); newActivity.AppUserID = Convert.ToInt32(objupd.UpdatedBy); newActivity.CreatedBy = objupd.UpdatedBy; newActivity.DateCreatedUTC = DateTime.UtcNow; newActivity.UpdatedBy = objupd.UpdatedBy; newActivity.LastUpdatedUTC = DateTime.UtcNow; newActivity.InvestigationID = targetObject.InvestigationID; newActivity.FromValue = objupd.PriorityTypeID.ToString(); newActivity.ToValue = targetObject.PriorityTypeID.ToString(); newActivity.ActivityTypeID = 7; // Category Type //Activities.Add(newActivity); _context.InvestigationActivity.Add(newActivity); hasChanges = true; } if (objupd.InvestigationDispositionsID != targetObject.InvestigationDispositionsID) // Disposition change { var newActivity = new InvestigationActivity(); newActivity.AppUserID = Convert.ToInt32(objupd.UpdatedBy); newActivity.CreatedBy = objupd.UpdatedBy; newActivity.DateCreatedUTC = DateTime.UtcNow; newActivity.UpdatedBy = objupd.UpdatedBy; newActivity.LastUpdatedUTC = DateTime.UtcNow; newActivity.InvestigationID = targetObject.InvestigationID; newActivity.FromValue = objupd.PriorityTypeID.ToString(); newActivity.ToValue = targetObject.PriorityTypeID.ToString(); newActivity.ActivityTypeID = 6; // Disposition Type //Activities.Add(newActivity); _context.InvestigationActivity.Add(newActivity); hasChanges = true; } if (hasChanges) { ReturnData ret; ret = _context.SaveData(); if (ret.Message == "Success") { return(Ok()); } return(NotFound(ret)); } return(NotFound()); }
public IActionResult Update([FromBody] InvestigationActivity editentry) { var result = _repository.Update(editentry, editentry.InvestigationActivityID); return(Helper.CheckResult(result)); }
public IActionResult Create([FromBody] InvestigationActivity newentry) { var result = _repository.Add(newentry); return(Helper.CheckResult(result)); }