public ActionResult AddAdditionalStudyIds(AddAdditionalStudyIdsModel model, IList <HttpPostedFileBase> files) { var isError = false; if (model.SiteId == "0" || string.IsNullOrEmpty(model.SiteId)) { ModelState.AddModelError("site", "*You must select a site"); isError = true; } var siteCode = DbUtils.GetSiteCodeForSite(int.Parse(model.SiteId)); if (!isError) { var dto = Business.Site.AddAdditionalStudyIds(files, model, siteCode); if (dto.ReturnValue == 0) { foreach (var d in dto.Dictionary) { ModelState.AddModelError(d.Key, d.Value); } isError = true; } } if (!isError) { return(RedirectToAction("AddAdditionalStudyIdsConfirmSuccess")); } var sites = DbUtils.GetSitesActive(); sites.Insert(0, new Site { ID = 0, Name = "Select a site", SiteID = "" }); var selectList = DbUtils.GetSitesActiveListItems(sites); model.Sites = selectList; return(View(model)); }
public ActionResult AddAdditionalStudyIds(string siteId) { if (siteId == null) { siteId = ""; } var sites = DbUtils.GetSitesActive(); sites.Insert(0, new Site { ID = 0, Name = "Select a site", SiteID = "" }); var selectList = DbUtils.GetSitesActiveListItems(sites); var model = new AddAdditionalStudyIdsModel { Sites = selectList, SiteId = siteId }; return(View(model)); }
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); }