public static MessageListDTO SaveStaffSubscriptions(StaffSubscriptions subs) { var dto = new MessageListDTO(); var strConn = ConfigurationManager.ConnectionStrings["Halfpint"].ToString(); using (var conn = new SqlConnection(strConn)) { conn.Open(); using (var trn = conn.BeginTransaction()) { try { var cmd = new SqlCommand("", conn) { Transaction = trn, CommandType = System.Data.CommandType.StoredProcedure, CommandText = "DeleteStaffSubscriptions" }; var param = new SqlParameter("@staffId", subs.StaffId); cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); foreach (var evnt in subs.NotificationEvents) { if (evnt.IsSubscribed) { cmd = new SqlCommand("", conn); cmd.Transaction = trn; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "AddStaffNotification"; param = new SqlParameter("@staffId", subs.StaffId); cmd.Parameters.Add(param); param = new SqlParameter("@eventId", evnt.Id); cmd.Parameters.Add(param); param = new SqlParameter("@allSites", evnt.IsAllSites); cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); } } trn.Commit(); } catch (Exception ex) { trn.Rollback(); Nlogger.LogError(ex); dto.IsSuccessful = false; dto.Dictionary.Add("StaffSubscriptions", "There was an error in SaveStaffSubscriptions"); return(dto); } } } dto.Messages.Add("Staff subscriptions were successfully saved to the database!"); dto.IsSuccessful = true; return(dto); }
public MessageListDTOQueryObject() { var messageListDTO = new MessageListDTO(); //Связываем поля dto объекта с правилами сортировки AddOrdering(messageListDTO.GetPropertyName(n => n.SendDate), n => n.SendDate); AddOrdering(messageListDTO.GetPropertyName(n => n.ReceiverName), n => n.Receiver.FirstName); AddOrdering(messageListDTO.GetPropertyName(n => n.SenderName), n => n.Sender.FirstName); AddOrdering(messageListDTO.GetPropertyName(n => n.Subject), n => n.Subject); }
private static bool AddStudyidsToDb(List <string> studyidLines, int siteId, MessageListDTO dto) { foreach (var line in studyidLines) { if (!DbUtils.AddStudyId(line, siteId, dto)) { return(false); } } return(true); }
public ActionResult AddStaff(StaffModel model) { if (model.Role == "Select a role") { ModelState["Role"].Errors.Add("Role is required"); } //validate model if (ModelState.IsValid) { MessageListDTO dto = DbUtils.AddStaff(model); if (dto.IsSuccessful) { //send email notification if (model.SendEmail) { Utility.SendAccountCreatedMail(new string[] { model.Email }, null, dto.Bag.ToString(), model.UserName, Utility.GetSiteLogonUrl(this.Request), this.Server); } } return(View("NewStaffConfirmation", dto)); } List <Site> sites = new List <Site>(); sites = DbUtils.GetSitesActive(); if (sites.Count == 0) { throw new Exception("There was an error retreiving the sites list from the database"); } sites.Insert(0, new Site { ID = 0, Name = "Select a site", SiteID = "" }); ViewBag.Sites = new SelectList(sites, "ID", "Name", model.SiteID); var roles = Roles.GetAllRoles().ToList(); roles.Insert(0, "Select a role"); ViewBag.Roles = new SelectList(roles, model.Role); return(View(model)); }
public ActionResult UpdateStaffInformation([Bind(Exclude = "SiteID,OldRole,OldActive,SendEmail," + "UserName,OldUserName,OldEmail,OldEmployeeID," + "PostTestsCompleted,PostTestsCompletedHistory")] StaffEditModel model) { //validate model if (ModelState.IsValid) { MessageListDTO dto = DbUtils.UpdateStaffAdmin(model); if (dto.IsSuccessful) { } if (model.Email != model.OldEmail) { DTO dtoEmail = null; if (model.UserName != null) { dtoEmail = AccountUtils.UpdateUserEmail(model.Email, model.UserName); } } if (model.Role != model.OldRole) { if (model.UserName != null) { string[] newroles = { model.Role }; UserRolesUtils.SaveAsignedRoles(newroles, model.UserName); } } if (model.OldActive != model.Active) { if (model.UserName != null) { var mUser = Membership.GetUser(model.UserName); if (mUser != null) { mUser.IsApproved = model.Active; Membership.UpdateUser(mUser); } } } return(View("UpdateStaffConfirmationPartial", dto)); } //ViewBag.Error = error; string role = ""; if (HttpContext.User.IsInRole("Admin")) { role = "Admin"; var sites = DbUtils.GetSitesActive(); if (sites.Count == 0) { throw new Exception("There was an error retreiving the sites list from the database"); } sites.Insert(0, new Site { ID = 0, Name = "Select a site", SiteID = "" }); ViewBag.Sites = new SelectList(sites, "ID", "Name"); } ViewBag.Role = role; int site = DbUtils.GetSiteidIdForUser(User.Identity.Name); ViewBag.Site = site; var retDto = DbPostTestsUtils.GetSiteEmployeeInfoForSite(site.ToString()); ViewBag.EmpRequired = retDto.Stuff.EmpIDRequired; if (retDto.Stuff.EmpIDRequired == "true") { ViewBag.EmpRegex = retDto.Stuff.EmpIDRegex; ViewBag.EmpMessage = retDto.Stuff.EmpIDMessage; } else { ViewBag.EmpRegex = ""; ViewBag.EmpMessage = ""; } ViewBag.PhoneMessage = retDto.Stuff.PhoneMessage; ViewBag.PhoneFormat = retDto.Stuff.PhoneFormat; var list = DbUtils.GetStaffLookupForSite(site.ToString()); list.Insert(0, new Site { ID = 0, Name = "Select a member", SiteID = "" }); ViewBag.Users = new SelectList(list, "ID", "Name", model.ID.ToString()); ViewBag.IsValid = "false"; //need to get tests completed for model - this was not returned from the client var postTestsCompleted = DbPostTestsUtils.GetTestsCompleted(model.ID.ToString()); PostTestPersonTestsCompleted ptpc = new PostTestPersonTestsCompleted(); ptpc.PostTestsCompleted = postTestsCompleted; model.PostTestsCompleted = ptpc; var roles = Roles.GetAllRoles().ToList(); ViewBag.Roles = new SelectList(roles, model.Role); return(View(model)); }
public static MessageListDTO Add(IList <HttpPostedFileBase> files, SiteInfo siteInfo, Uri url) { var dto = new MessageListDTO { ReturnValue = 1 }; //this is used to mark all randomizaions as arm 1 for the test site bool isTestSite = url.LocalPath.Contains("hpTest"); using (var scope = new TransactionScope()) { try { //check for duplicate name var retVal = DbUtils.IsSiteNameDuplicate(siteInfo.Name); if (retVal != 0) { if (retVal == 1) { dto.Dictionary.Add("Name", siteInfo.Name + " is already in the database"); } else { dto.Dictionary.Add("Name", "There was a problem checking for a duplicate name"); } dto.ReturnValue = 0; scope.Dispose(); return(dto); } //check for duplicat site id retVal = DbUtils.IsSiteIdDuplicate(siteInfo.SiteId); if (retVal != 0) { if (retVal == 1) { dto.Dictionary.Add("SiteId", siteInfo.SiteId + " is already being used for site ID"); } else { dto.Dictionary.Add("SiteId", "There was a problem checking for a duplicate site ID"); } dto.ReturnValue = 0; scope.Dispose(); return(dto); } //check for import files if (files[0] == null || files[1] == null) { dto.Dictionary.Add("importFiles", "One or both import files are missing"); dto.ReturnValue = 0; scope.Dispose(); return(dto); } //study ids import file string fileName = files[0].FileName.ToLower(); if (!fileName.Contains("studyids")) { dto.Dictionary.Add("importFiles", "The study id's import file name is not correct, it must be named: studyids" + siteInfo.SiteId + ".cvs"); dto.ReturnValue = 0; scope.Dispose(); return(dto); } //randomization import file fileName = files[1].FileName.ToLower(); if (!fileName.Contains("randomizations")) { dto.Dictionary.Add("importFiles", "The radomization's import file name is not correct, it must be named: randomizations" + siteInfo.SiteId + ".cvs"); dto.ReturnValue = 0; scope.Dispose(); return(dto); } dto = DbUtils.AddSiteInfo(siteInfo); if (dto.ReturnValue < 1) { scope.Dispose(); return(dto); } //check format and parse var studyidLines = CheckFileFormatStudyId(files[0], siteInfo.SiteId, dto); if (dto.ReturnValue == 0) { scope.Dispose(); return(dto); } if (DbUtils.DoesStudyIdsExistForSite(siteInfo.Id, dto) != 0) { scope.Dispose(); return(dto); } if (!AddStudyidsToDb(studyidLines, siteInfo.Id, dto)) { scope.Dispose(); return(dto); } //check format and parse var randomizations = CheckFileFormatRandomization(files[1], siteInfo.SiteId, dto, isTestSite); if (dto.ReturnValue == 0) { scope.Dispose(); return(dto); } if (DbUtils.DoesRandomizationsExistForSite(siteInfo.Id, dto) != 0) { scope.Dispose(); return(dto); } if (!AddRandomizationsToDb(randomizations, siteInfo.Id, dto)) { scope.Dispose(); return(dto); } dto.IsSuccessful = true; scope.Complete(); } catch (Exception) { scope.Dispose(); } } return(dto); }
private static List <string> CheckFileFormatStudyId(HttpPostedFileBase file, string siteId, MessageListDTO dto) { using (var srdr = new StreamReader(file.InputStream)) { //var count = 0; var lines = new List <string>(); while (true) { //count++; var line = srdr.ReadLine(); if (line == null) { break; } if (line.Length == 0) { continue; } var sParts = line.Split(new string[] { "-" }, StringSplitOptions.None); string sPartSiteId = sParts[0]; if (sPartSiteId != siteId) { dto.Dictionary.Add("importFiles", "The study id's do not begin with the correct site id. They begin with " + sPartSiteId + ", they should begin with " + siteId + "."); dto.ReturnValue = 0; return(null); } lines.Add(line.Trim()); } return(lines); } }
private static List <string> CheckFileFormatAdditionalStudyId(HttpPostedFileBase file, string siteCode, MessageListDTO dto, int low, int high) { using (var srdr = new StreamReader(file.InputStream)) { var count = low; var lines = new List <string>(); while (true) { var line = srdr.ReadLine(); if (line == null) { break; } if (line.Length == 0) { continue; } var sParts = line.Split(new string[] { "-" }, StringSplitOptions.None); string sPartSiteId = sParts[0]; if (sPartSiteId != siteCode) { dto.Dictionary.Add("importFiles", "The study id's do not begin with the correct site id. They begin with " + sPartSiteId + ", they should begin with " + siteCode + "."); dto.ReturnValue = 0; return(null); } int id; if (int.TryParse(sParts[1], out id)) { if (id != count) { dto.Dictionary.Add("importFiles", "The study id's are not in consecutive order or does not start with " + low + ", there is a problem on study id " + count); dto.ReturnValue = 0; return(null); } } else { dto.Dictionary.Add("importFiles", "There is a problem with the study id's, the problem seems to be with study id " + count); dto.ReturnValue = 0; return(null); } lines.Add(line.Trim()); count++; } return(lines); } }
private static List <RandomizationLines> CheckFileFormatRandomization(HttpPostedFileBase file, string siteId, MessageListDTO dto, bool isTestSite) { var randomizations = new List <RandomizationLines>(); using (var srdr = new StreamReader(file.InputStream)) { //var count = 0; var lines = new List <string>(); while (true) { //count++; var line = srdr.ReadLine(); if (line == null) { break; } if (line.Length == 0) { continue; } var sCols = line.Split(new string[] { "," }, StringSplitOptions.None); var numberCol = sCols[1]; var sParts = numberCol.Split(new string[] { "-" }, StringSplitOptions.None); string sPartSiteId = sParts[0]; if (sPartSiteId != siteId) { dto.Dictionary.Add("importFiles", "The randomizations do not begin with the correct site id. They begin with " + sPartSiteId + ", they should begin with " + siteId + "."); dto.ReturnValue = 0; return(null); } var rndmz = new RandomizationLines(); rndmz.Number = numberCol; string armCol = sCols[8]; if (!(armCol == "TGC-1" || armCol == "TGC-2")) { dto.Dictionary.Add("importFiles", "The randomizations arm column are not valid. Found " + armCol + ", should be either TGC-1 or TGC-2."); dto.ReturnValue = 0; return(null); } if (isTestSite) { armCol = "TGC-1"; } rndmz.Arm = armCol; randomizations.Add(rndmz); } return(randomizations); } }
private static bool AddRandomizationsToDb(List <RandomizationLines> randomizations, int siteId, MessageListDTO dto) { foreach (var randomization in randomizations) { if (!DbUtils.AddRandomizationForNewSite(randomization.Number, randomization.Arm, siteId, dto)) { return(false); } } return(true); }
public static MessageListDTO AddAdditionalStudyIds(IList <HttpPostedFileBase> files, AddAdditionalStudyIdsModel model, string siteCode) { var dto = new MessageListDTO { ReturnValue = 1 }; //check for file if (files[0] == null) { dto.Dictionary.Add("file", "*You must select a file"); dto.ReturnValue = 0; return(dto); } var file = files[0]; if (!file.FileName.ToLower().StartsWith("studyids")) { dto.Dictionary.Add("importFiles", "*The study id's import file name is not correct, it must be named: studyids" + siteCode + "_firstId-lastId.cvs example:studyids" + siteCode + "_2501-5000"); dto.ReturnValue = 0; return(dto); } var aParts = file.FileName.Split('_'); if (!aParts[0].EndsWith(siteCode)) { dto.Dictionary.Add("importFiles", "*The study id's import file does not contain the correct site id, the correct site id is " + siteCode); dto.ReturnValue = 0; return(dto); } var bParts = aParts[1].Split('-'); int lowId; int highId; if (!int.TryParse(bParts[0], out lowId)) { dto.Dictionary.Add("importFiles", "*The study id's import file name is not correct, it must be named: studyids" + siteCode + "_firstId-lastId.cvs example:studyids" + siteCode + "_2501-5000"); dto.ReturnValue = 0; return(dto); } var sHigh = bParts[1].Split('.')[0]; if (!int.TryParse(sHigh, out highId)) { dto.Dictionary.Add("importFiles", "*The study id's import file name is not correct, it must be named: studyids" + siteCode + "_firstId-lastId.cvs example:studyids" + siteCode + "_2501-5000"); dto.ReturnValue = 0; return(dto); } if (lowId > highId) { dto.Dictionary.Add("importFiles", "*The study id's import file name is not correct, it must be named: studyids" + siteCode + "_firstId-lastId.cvs example:studyids" + siteCode + "_2501-5000"); dto.ReturnValue = 0; return(dto); } //check format and parse var studyidLines = CheckFileFormatAdditionalStudyId(files[0], siteCode, dto, lowId, highId); if (dto.ReturnValue == 0) { dto.ReturnValue = 0; return(dto); } //check to see if id's already exist in the db if (DbUtils.IsStudyIdDuplicate(studyidLines[0])) { dto.Dictionary.Add("importFiles", "*The study id " + studyidLines[0] + " is already in the database. Make sure these study id's are not in the database."); dto.ReturnValue = 0; return(dto); } if (!AddStudyidsToDb(studyidLines, int.Parse(model.SiteId), dto)) { dto.ReturnValue = 0; return(dto); } return(dto); }
public ActionResult UpdateStaffInformation([Bind(Exclude = "SiteID,OldRole,OldActive,SendEmail," + "UserName,OldUserName,OldEmail,OldEmployeeID," + "PostTestsCompleted,PostTestsCompletedHistory")] StaffEditModel model) { //validate model if (ModelState.IsValid) { if (model.Role != "Nurse") { model.Email = model.OldEmail; model.Active = model.OldActive; } MessageListDTO dto = DbUtils.UpdateStaff(model); if (dto.IsSuccessful) { } if (model.OldActive != model.Active) { if (model.UserName != null) { var mUser = Membership.GetUser(model.UserName); if (mUser != null) { mUser.IsApproved = model.Active; Membership.UpdateUser(mUser); } } } return(View("UpdateStaffConfirmationPartial", dto)); } //ModelState.AddModelError("FirstName", "Test Error"); //string key1 = ""; //string error = ""; //foreach (var m in ModelState) //{ // if (m.Value.Errors.Count > 0) // { // key1 = m.Key; // error = key1 + ":" + m.Value.Errors[0].ErrorMessage; // } //} //ViewBag.Error = error; string role = ""; if (HttpContext.User.IsInRole("Admin")) { role = "Admin"; var sites = DbUtils.GetSitesActive(); if (sites.Count == 0) { throw new Exception("There was an error retreiving the sites list from the database"); } sites.Insert(0, new Site { ID = 0, Name = "Select a site", SiteID = "" }); ViewBag.Sites = new SelectList(sites, "ID", "Name"); } ViewBag.Role = role; int site = DbUtils.GetSiteidIdForUser(User.Identity.Name); ViewBag.Site = site; var list = DbUtils.GetStaffLookupForSite(site.ToString()); list.Insert(0, new Site { ID = 0, Name = "Select a member", SiteID = "" }); ViewBag.Users = new SelectList(list, "ID", "Name", model.ID.ToString()); ViewBag.IsValid = "false"; //need to get tests completed for model - this was not returned from the client var postTestsCompleted = DbPostTestsUtils.GetTestsCompleted(model.ID.ToString()); var ptpc = new PostTestPersonTestsCompleted(); ptpc.PostTestsCompleted = postTestsCompleted; model.PostTestsCompleted = ptpc; return(View(model)); }