public DocTemplateModel GetDocTemplateModelExistDB(DocTemplateModel docTemplateModel) { DocTemplateModel docTemplateModelRet = (from c in db.DocTemplates where c.TVType == (int)docTemplateModel.TVType && c.FileName == docTemplateModel.FileName select new DocTemplateModel { Error = "", DocTemplateID = c.DocTemplateID, DBCommand = (DBCommandEnum)c.DBCommand, Language = (LanguageEnum)c.Language, TVType = (TVTypeEnum)c.TVType, TVFileTVItemID = c.TVFileTVItemID, FileName = c.FileName, LastUpdateDate_UTC = c.LastUpdateDate_UTC, LastUpdateContactTVItemID = c.LastUpdateContactTVItemID, }).FirstOrDefault <DocTemplateModel>(); if (docTemplateModelRet == null) { return(ReturnError(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.DocTemplate, ServiceRes.TVType + "," + ServiceRes.FileName, docTemplateModel.TVType.ToString() + "," + docTemplateModel.FileName))); } return(docTemplateModelRet); }
// Check public string DocTemplateModelOK(DocTemplateModel docTemplateModel) { string retStr = _BaseEnumService.LanguageOK(docTemplateModel.Language); if (!string.IsNullOrWhiteSpace(retStr)) { return(retStr); } retStr = _BaseEnumService.TVTypeOK(docTemplateModel.TVType); if (!string.IsNullOrWhiteSpace(retStr)) { return(retStr); } retStr = FieldCheckIfNotNullNotZeroInt(docTemplateModel.TVFileTVItemID, ServiceRes.TVFileTVItemID); if (!string.IsNullOrWhiteSpace(retStr)) { return(retStr); } retStr = FieldCheckNotEmptyAndMaxLengthString(docTemplateModel.FileName, ServiceRes.FileName, 150); if (!string.IsNullOrWhiteSpace(retStr)) { return(retStr); } retStr = _BaseEnumService.DBCommandOK(docTemplateModel.DBCommand); if (!string.IsNullOrWhiteSpace(retStr)) { return(retStr); } return(""); }
public DocTemplateModel GetDocTemplateModelWithDocTemplateIDDB(int DocTemplateID) { DocTemplateModel docTemplateModel = (from c in db.DocTemplates where c.DocTemplateID == DocTemplateID orderby c.TVType, c.FileName select new DocTemplateModel { Error = "", DocTemplateID = c.DocTemplateID, DBCommand = (DBCommandEnum)c.DBCommand, Language = (LanguageEnum)c.Language, TVType = (TVTypeEnum)c.TVType, TVFileTVItemID = c.TVFileTVItemID, FileName = c.FileName, LastUpdateDate_UTC = c.LastUpdateDate_UTC, LastUpdateContactTVItemID = c.LastUpdateContactTVItemID, }).FirstOrDefault <DocTemplateModel>(); if (docTemplateModel == null) { return(ReturnError(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.DocTemplate, ServiceRes.DocTemplateID, DocTemplateID.ToString()))); } return(docTemplateModel); }
// Post //public DocTemplateModel DocTemplateAddOrModifyDB(FormCollection fc) //{ // int tempInt = 0; // int DocTemplateID = 0; // TVTypeEnum TVType = TVTypeEnum.Error; // string FileName = ""; // ContactOK contactOK = IsContactOK(); // if (!string.IsNullOrWhiteSpace(contactOK.Error)) // return ReturnError(contactOK.Error); // int.TryParse(fc["DocTemplateID"], out DocTemplateID); // // can be 0 if adding a new DocTemplate // int.TryParse(fc["TVType"], out tempInt); // if (tempInt == 0) // return ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.TVType)); // TVType = (TVTypeEnum)tempInt; // FileName = fc["FileName"]; // if (string.IsNullOrWhiteSpace(FileName)) // return ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.FileName)); // TVItemModel TVItemRoot = _TVItemService.GetRootTVItemModelDB(); // if (!string.IsNullOrWhiteSpace(TVItemRoot.Error)) // return ReturnError(TVItemRoot.Error); // DocTemplateModel docTemplateModel = new DocTemplateModel(); // using (TransactionScope ts = new TransactionScope()) // { // string ObservationInfo = ((int)PolSourceObsInfoEnum.LandBased).ToString() + ","; // List<int> obsIntList = ObservationInfo.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList(); // string ObservationLanguageTVText = ServiceRes.Error; // string TVText = _BaseEnumService.GetEnumText_PolSourceObsInfoTextEnum(PolSourceObsInfoEnum.Error); // int NextSiteNumber = 0; // if (DocTemplateID == 0) // { // DocTemplateModel docTemplateModelNew = new DocTemplateModel() // { // TVType = (int)TVType, // FileName = FileName, // }; // // Automatically add one Pollution Source Observation for today // PolSourceObservationModel polSourceObservationModelNew = new PolSourceObservationModel() // { // PolSourceSiteTVItemID = polSourceSiteNewOrToChange.PolSourceSiteTVItemID, // ObservationDate_Local = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day), // ContactTVItemID = contactOK.ContactTVItemID, // Observation_ToBeDeleted = "", // }; // PolSourceObservationModel polSourceObservationModelRet = _PolSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew); // if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet.Error)) // return ReturnError(polSourceObservationModelRet.Error); // // Automatically add one Pollution Source Observation Issue // PolSourceObservationIssueModel polSourceObservationIssueModelNew = new PolSourceObservationIssueModel(); // polSourceObservationIssueModelNew.PolSourceObservationID = polSourceObservationModelRet.PolSourceObservationID; // polSourceObservationIssueModelNew.ObservationInfo = ObservationInfo; // polSourceObservationIssueModelNew.Ordinal = 0; // PolSourceObservationIssueModel polSourceObservationIssueModelRet = _PolSourceObservationService._PolSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew); // if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet.Error)) // return ReturnError(polSourceObservationIssueModelRet.Error); // // doing the other language // foreach (string lang in LanguageListAllowable.Where(c => c != LanguageRequest)) // { // TVItemService tvItemService = new TVItemService(lang, _TVItemService.User); // Thread.CurrentThread.CurrentCulture = new CultureInfo(lang + "-CA"); // Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang + "-CA"); // ObservationInfo = ((int)PolSourceObsInfoEnum.LandBased).ToString() + ","; // ObservationLanguageTVText = ServiceRes.Error; // TVText = _BaseEnumService.GetEnumText_PolSourceObsInfoTextEnum(PolSourceObsInfoEnum.Error); // TVText = (string.IsNullOrWhiteSpace(TVText) ? ServiceRes.Error : TVText); // if (PolSourceSiteTVItemID == 0) // { // TVText = TVText + " - " + "000000".Substring(0, "000000".Length - NextSiteNumber.ToString().Length) + NextSiteNumber.ToString(); // } // else // { // TVText = TVText + " - " + "000000".Substring(0, "000000".Length - polSourceSiteNewOrToChange.Site.ToString().Length) + polSourceSiteNewOrToChange.Site.ToString(); // } // TVItemLanguageModel tvItemLanguageModel = new TVItemLanguageModel(); // tvItemLanguageModel.Language = lang; // tvItemLanguageModel.TVText = TVText; // tvItemLanguageModel.TVItemID = polSourceSiteNewOrToChange.PolSourceSiteTVItemID; // TVItemLanguageModel tvItemLanguageModelRet = tvItemService._TVItemLanguageService.PostUpdateTVItemLanguageDB(tvItemLanguageModel); // if (!string.IsNullOrWhiteSpace(tvItemLanguageModelRet.Error)) // return ReturnError(tvItemLanguageModelRet.Error); // Thread.CurrentThread.CurrentCulture = new CultureInfo(LanguageRequest + "-CA"); // Thread.CurrentThread.CurrentUICulture = new CultureInfo(LanguageRequest + "-CA"); // } // } // else // { // polSourceSiteNewOrToChange = PostUpdatePolSourceSiteDB(polSourceSiteNewOrToChange); // if (!string.IsNullOrWhiteSpace(polSourceSiteNewOrToChange.Error)) // return ReturnError(polSourceSiteNewOrToChange.Error); // } // // Adding map info // List<MapInfoPointModel> mapInfoPointModelList = _MapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(polSourceSiteNewOrToChange.PolSourceSiteTVItemID, TVTypeEnum.PolSourceSite, MapInfoDrawTypeEnum.Point); // if (mapInfoPointModelList.Count == 0) // { // MapInfoModel mapInfoModelRet = _MapInfoService.CreateMapInfoObjectDB(coordList, MapInfoDrawTypeEnum.Point, TVTypeEnum.PolSourceSite, polSourceSiteNewOrToChange.PolSourceSiteTVItemID); // if (!string.IsNullOrWhiteSpace(mapInfoModelRet.Error)) // return ReturnError(mapInfoModelRet.Error); // } // else // { // mapInfoPointModelList[0].Lat = coordList[0].Lat; // mapInfoPointModelList[0].Lng = coordList[0].Lng; // MapInfoPointModel mapInfoPointModelRet = _MapInfoService._MapInfoPointService.PostUpdateMapInfoPointDB(mapInfoPointModelList[0]); // if (!string.IsNullOrWhiteSpace(mapInfoPointModelRet.Error)) // return ReturnError(mapInfoPointModelRet.Error); // } // TVItemModel tvItemModelPolSourceSite = _TVItemService.GetTVItemModelWithTVItemIDDB(polSourceSiteNewOrToChange.PolSourceSiteTVItemID); // if (!string.IsNullOrWhiteSpace(tvItemModelPolSourceSite.Error)) // return ReturnError(tvItemModelPolSourceSite.Error); // tvItemModelPolSourceSite.IsActive = IsActive; // TVItemModel tvItemModelRet = _TVItemService.PostUpdateTVItemDB(tvItemModelPolSourceSite); // if (!string.IsNullOrWhiteSpace(tvItemModelRet.Error)) // return ReturnError(tvItemModelRet.Error); // ts.Complete(); // } // return polSourceSiteNewOrToChange; //} public DocTemplateModel PostAddDocTemplateDB(DocTemplateModel docTemplateModel) { string retStr = DocTemplateModelOK(docTemplateModel); if (!string.IsNullOrEmpty(retStr)) { return(ReturnError(retStr)); } ContactOK contactOK = IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(ReturnError(contactOK.Error)); } TVFileModel tvFileModel = _TVFileService.GetTVFileModelWithTVFileTVItemIDDB(docTemplateModel.TVFileTVItemID); if (!string.IsNullOrWhiteSpace(tvFileModel.Error)) { return(ReturnError(tvFileModel.Error)); } DocTemplateModel docTemplateModelExist = GetDocTemplateModelExistDB(docTemplateModel); if (string.IsNullOrWhiteSpace(docTemplateModelExist.Error)) { return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.DocTemplate))); } DocTemplate docTemplateNew = new DocTemplate(); retStr = FillDocTemplate(docTemplateNew, docTemplateModel, contactOK); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } using (TransactionScope ts = new TransactionScope()) { db.DocTemplates.Add(docTemplateNew); retStr = DoAddChanges(); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } LogModel logModel = _LogService.PostAddLogForObj("DocTemplates", docTemplateNew.DocTemplateID, LogCommandEnum.Add, docTemplateNew); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetDocTemplateModelWithDocTemplateIDDB(docTemplateNew.DocTemplateID)); }
public DocTemplateModel PostDeleteDocTemplateWithTVFileTVItemIDDB(int TVFileTVItemID) { ContactOK contactOK = IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(ReturnError(contactOK.Error)); } DocTemplateModel docTemplateModelToDelete = GetDocTemplateModelWithTVFileTVItemIDDB(TVFileTVItemID); if (!string.IsNullOrWhiteSpace(docTemplateModelToDelete.Error)) { return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToDelete, ServiceRes.DocTemplate))); } return(PostDeleteDocTemplateWithDocTemplateIDDB(docTemplateModelToDelete.DocTemplateID)); }
// Fill public string FillDocTemplate(DocTemplate docTemplate, DocTemplateModel docTemplateModel, ContactOK contactOK) { docTemplate.DBCommand = (int)docTemplateModel.DBCommand; docTemplate.Language = (int)docTemplateModel.Language; docTemplate.TVType = (int)docTemplateModel.TVType; docTemplate.TVFileTVItemID = docTemplateModel.TVFileTVItemID; docTemplate.FileName = docTemplateModel.FileName; docTemplate.LastUpdateDate_UTC = DateTime.UtcNow; if (contactOK == null) { docTemplate.LastUpdateContactTVItemID = 2; } else { docTemplate.LastUpdateContactTVItemID = contactOK.ContactTVItemID; } return(""); }
/// <summary> /// 获取文书模板信息 /// </summary> /// <param name="wsmbbh"></param> /// <param name="errmsg"></param> /// <returns></returns> public static DocTemplateModel GetDocmbInfo(string wsmbbh, out string errmsg) { errmsg = string.Empty; DocTemplateModel docInfo = null; DataTable dt = null; ParamConvert pc = new ParamConvert(); pc.Basic(true); pc.Add("p_wsmbbh", wsmbbh); try { dt = pc.DoExecuteDataTable("PKG_DOC_MANAGE.proc_get_mbifo"); errmsg += Convert.ToString(pc.GetValueByKey("p_errmsg")); } catch (Exception e) { errmsg += e.Message; } if (string.IsNullOrEmpty(errmsg) && dt != null && dt.Rows.Count == 1) { docInfo = ModelHandler.FillModel <DocTemplateModel>(dt.Rows[0]); } return(docInfo); }
public void FileController_CreateDocumentFromTemplateJSON_Canada_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { controllerAction = "CreateDocumentFromTemplateJSON"; contactModel = contactModelListGood[0]; SetupTest(contactModel, culture, controllerAction); using (TransactionScope ts = new TransactionScope()) { TVItemModel tvItemModelRoot = tvItemService.GetRootTVItemModelDB(); Assert.AreEqual("", tvItemModelRoot.Error); TVItemModel tvItemModelCanada = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, "Canada", TVTypeEnum.Country); Assert.AreEqual("", tvItemModelRoot.Error); DirectoryInfo di = new DirectoryInfo(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID)); if (!di.Exists) { di.Create(); } di = new DirectoryInfo(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID)); Assert.IsTrue(di.Exists); FileInfo fi = new FileInfo(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID) + "this_should_be_unique.docx"); if (!fi.Exists) { StreamWriter sw = new StreamWriter(fi.FullName); sw.WriteLine("|||Testing document|||"); sw.Close(); } string FileName = "this_should_be_unique.docx"; fi = new FileInfo(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID) + FileName); Assert.IsTrue(fi.Exists); TVItemModel tvItemModelFile = tvItemService.PostAddChildTVItemDB(tvItemModelRoot.TVItemID, FileName, TVTypeEnum.File); Assert.AreEqual("", tvItemModelFile.Error); TVFileModel tvFileModelNew = new TVFileModel(); tvFileModelNew.TVFileTVItemID = tvItemModelFile.TVItemID; FillTVFileModel(tvFileModelNew); tvFileModelNew.Language = controller.LanguageRequest; tvFileModelNew.FilePurpose = FilePurposeEnum.Template; tvFileModelNew.FileType = FileTypeEnum.DOCX; tvFileModelNew.FileDescription = randomService.RandomString("File Description", 200); tvFileModelNew.FileSize_kb = (int)(fi.Length / 1024); tvFileModelNew.FileInfo = randomService.RandomString("File Info", 200); tvFileModelNew.FileCreatedDate_UTC = DateTime.Now; tvFileModelNew.ClientFilePath = ""; tvFileModelNew.ServerFileName = FileName; tvFileModelNew.ServerFilePath = tvFileService.ChoseEDriveOrCDrive(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID)); TVFileModel tvFileModelRet = tvFileService.PostAddTVFileDB(tvFileModelNew); Assert.AreEqual("", tvFileModelRet.Error); DocTemplateModel docTemplateModelNew = new DocTemplateModel() { TVType = tvItemModelCanada.TVType, TVFileTVItemID = tvFileModelRet.TVFileTVItemID, FileName = FileName, }; DocTemplateModel docTemplateModelRet = docTemplateService.PostAddDocTemplateDB(docTemplateModelNew); Assert.AreEqual("", docTemplateModelRet.Error); System.Web.Mvc.FormCollection fc = new System.Web.Mvc.FormCollection(); fc.Add("TVItemID", tvItemModelCanada.TVItemID.ToString()); fc.Add("DocTemplateID", docTemplateModelRet.DocTemplateID.ToString()); JsonResult jsonResult = controller.CreateDocumentFromTemplateJSON(fc) as JsonResult; Assert.IsNotNull(jsonResult); string retStr = (string)jsonResult.Data; Assert.AreEqual("", retStr); AppTaskModel appTaskModel = appTaskService.GetAppTaskModelWithTVItemIDTVItemID2AndCommandDB(tvItemModelCanada.TVItemID, tvItemModelCanada.TVItemID, AppTaskCommandEnum.CreateDocumentFromTemplate); Assert.AreEqual("", appTaskModel.Error); Assert.AreEqual("", appTaskModel.Error); } } }
public void FileController__createDocument_Canada_Word_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { controllerAction = "_createDocument"; contactModel = contactModelListGood[0]; SetupTest(contactModel, culture, controllerAction); using (TransactionScope ts = new TransactionScope()) { TVItemModel tvItemModelRoot = tvItemService.GetRootTVItemModelDB(); Assert.AreEqual("", tvItemModelRoot.Error); TVItemModel tvItemModelCanada = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, "Canada", TVTypeEnum.Country); Assert.AreEqual("", tvItemModelRoot.Error); DirectoryInfo di = new DirectoryInfo(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID)); if (!di.Exists) { di.Create(); } di = new DirectoryInfo(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID)); Assert.IsTrue(di.Exists); FileInfo fi = new FileInfo(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID) + "this_should_be_unique.docx"); if (!fi.Exists) { StreamWriter sw = new StreamWriter(fi.FullName); sw.WriteLine("|||Testing document|||"); sw.Close(); } string FileName = "this_should_be_unique.docx"; fi = new FileInfo(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID) + FileName); Assert.IsTrue(fi.Exists); TVItemModel tvItemModelFile = tvItemService.PostAddChildTVItemDB(tvItemModelRoot.TVItemID, FileName, TVTypeEnum.File); Assert.AreEqual("", tvItemModelFile.Error); TVFileModel tvFileModelNew = new TVFileModel(); tvFileModelNew.TVFileTVItemID = tvItemModelFile.TVItemID; FillTVFileModel(tvFileModelNew); tvFileModelNew.Language = controller.LanguageRequest; tvFileModelNew.FilePurpose = FilePurposeEnum.Template; tvFileModelNew.FileType = FileTypeEnum.DOCX; tvFileModelNew.FileDescription = randomService.RandomString("File Description", 200); tvFileModelNew.FileSize_kb = (int)(fi.Length / 1024); tvFileModelNew.FileInfo = randomService.RandomString("File Info", 200); tvFileModelNew.FileCreatedDate_UTC = DateTime.Now; tvFileModelNew.ClientFilePath = ""; tvFileModelNew.ServerFileName = FileName; tvFileModelNew.ServerFilePath = tvFileService.ChoseEDriveOrCDrive(tvFileService.GetServerFilePath(tvItemModelRoot.TVItemID)); TVFileModel tvFileModelRet = tvFileService.PostAddTVFileDB(tvFileModelNew); Assert.AreEqual("", tvFileModelRet.Error); DocTemplateModel docTemplateModelNew = new DocTemplateModel() { TVType = tvItemModelCanada.TVType, TVFileTVItemID = tvFileModelRet.TVFileTVItemID, FileName = FileName, }; DocTemplateModel docTemplateModelRet = docTemplateService.PostAddDocTemplateDB(docTemplateModelNew); Assert.AreEqual("", docTemplateModelRet.Error); PartialViewResult partialViewResult = controller._createDocument(tvItemModelCanada.TVItemID) as PartialViewResult; Assert.IsNotNull(partialViewResult); FileController fileController = (FileController)partialViewResult.ViewBag.FileController; Assert.IsNotNull(fileController); TVItemModel tvItemModelRet = (TVItemModel)partialViewResult.ViewBag.TVItemModel; Assert.AreEqual("", tvItemModelRet.Error); Assert.AreEqual(tvItemModelRet.TVItemID, tvItemModelCanada.TVItemID); List <DocTemplateModel> docTemplateModelList = (List <DocTemplateModel>)partialViewResult.ViewBag.DocTemplateModelList; Assert.IsTrue(docTemplateModelList.Count > 0); fi.Delete(); } } }
public DocTemplateModel PostUpdateDocTemplateDB(DocTemplateModel docTemplateModel) { string retStr = DocTemplateModelOK(docTemplateModel); if (!string.IsNullOrEmpty(retStr)) { return(ReturnError(retStr)); } ContactOK contactOK = IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(ReturnError(contactOK.Error)); } TVFileModel tvFileModel = _TVFileService.GetTVFileModelWithTVFileTVItemIDDB(docTemplateModel.TVFileTVItemID); if (!string.IsNullOrWhiteSpace(tvFileModel.Error)) { return(ReturnError(tvFileModel.Error)); } DocTemplate docTemplateToUpdate = GetDocTemplateWithDocTemplateIDDB(docTemplateModel.DocTemplateID); if (docTemplateToUpdate == null) { return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.DocTemplate))); } retStr = FillDocTemplate(docTemplateToUpdate, docTemplateModel, contactOK); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } using (TransactionScope ts = new TransactionScope()) { if (tvFileModel.ServerFileName != docTemplateModel.FileName) { tvFileModel.ServerFileName = docTemplateModel.FileName; TVFileModel tvFileModelRet = _TVFileService.PostUpdateTVFileDB(tvFileModel); if (!string.IsNullOrWhiteSpace(tvFileModelRet.Error)) { return(ReturnError(tvFileModelRet.Error)); } } retStr = DoUpdateChanges(); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } LogModel logModel = _LogService.PostAddLogForObj("DocTemplates", docTemplateToUpdate.DocTemplateID, LogCommandEnum.Change, docTemplateToUpdate); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetDocTemplateModelWithDocTemplateIDDB(docTemplateToUpdate.DocTemplateID)); }
public string GenerateFileNameForDocTemplate(int DocTemplateID, int ParentTVItemID, string LanguageRequest) { List <string> ReplaceTextListWithUnderscore = new List <string>() { "#", "%", "&", "{", "}", "\\", "<", ">", "*", "?", "/", " ", "$", "!", "'", "\"", ":", "@", "+", "`", "|", "=" }; if (LanguageRequest == "fr") { Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA"); } else { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-CA"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA"); } DocTemplateModel docTemplateModel = GetDocTemplateModelWithDocTemplateIDDB(DocTemplateID); if (!string.IsNullOrWhiteSpace(docTemplateModel.Error)) { return("ERROR_" + docTemplateModel.Error.Replace(" ", "_")); } TVItemModel tvItemModelTemplateFile = _TVItemService.GetTVItemModelWithTVItemIDDB(docTemplateModel.TVFileTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelTemplateFile.Error)) { return("ERROR_" + tvItemModelTemplateFile.Error.Replace(" ", "_")); } TVItemModel tvItemModelParent = _TVItemService.GetTVItemModelWithTVItemIDDB(ParentTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelParent.Error)) { return("ERROR_" + tvItemModelParent.Error.Replace(" ", "_")); } TVFileModel tvFileModelTemplate = _TVFileService.GetTVFileModelWithTVFileTVItemIDDB(docTemplateModel.TVFileTVItemID); if (!string.IsNullOrWhiteSpace(tvFileModelTemplate.Error)) { return("ERROR_" + tvFileModelTemplate.Error.Replace(" ", "_")); } FileInfo fiTemplate = new FileInfo(_TVFileService.ChoseEDriveOrCDrive(_TVFileService.GetServerFilePath(tvItemModelTemplateFile.ParentID)) + tvFileModelTemplate.ServerFileName); if (!fiTemplate.Exists) { return("ERROR_" + string.Format(ServiceRes.CouldNotFind_, fiTemplate.FullName).Replace(" ", "_")); } DateTime DateUtc = DateTime.UtcNow; string FileName = tvFileModelTemplate.ServerFileName.Replace(fiTemplate.Extension.ToLower(), "") + "_" + DateUtc.Year.ToString() + "_" + (DateUtc.Month < 10 ? "0" + DateUtc.Month.ToString() : DateUtc.Month.ToString()) + "_" + (DateUtc.Day < 10 ? "0" + DateUtc.Day.ToString() : DateUtc.Day.ToString()) + "_" + (DateUtc.Hour < 10 ? "0" + DateUtc.Hour.ToString() : DateUtc.Hour.ToString()) + "_" + (DateUtc.Minute < 10 ? "0" + DateUtc.Minute.ToString() : DateUtc.Minute.ToString()) + "_" + LanguageRequest + fiTemplate.Extension.ToLower(); return(FileName); }
public TVFileModel FileUploadDB(FormCollection fc, HttpRequestBase Request) { ContactOK contactOK = _TVFileService.IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(_TVFileService.ReturnError(contactOK.Error)); } int ParentTVItemID = 0; int tempInt = 0; LanguageEnum Language = LanguageEnum.Error; FilePurposeEnum FilePurpose = FilePurposeEnum.Error; string FileDescription = ""; bool KeepFileName = true; string SaveAsFileName = ""; bool? FromWater = null; int? Year = null; int.TryParse(fc["ParentTVItemID"], out ParentTVItemID); if (ParentTVItemID == 0) { return new TVFileModel() { Error = string.Format(ServiceRes._IsRequired, ServiceRes.ParentTVItemID) } } ; int.TryParse(fc["Language"], out tempInt); if (tempInt == 0) { return new TVFileModel() { Error = string.Format(ServiceRes._IsRequired, ServiceRes.Language) } } ; Language = (LanguageEnum)tempInt; int.TryParse(fc["Year"], out tempInt); if (tempInt == 0) { return new TVFileModel() { Error = string.Format(ServiceRes._IsRequired, ServiceRes.Year) } } ; Year = tempInt; int.TryParse(fc["FilePurpose"], out tempInt); if (tempInt == 0) { return new TVFileModel() { Error = string.Format(ServiceRes._IsRequired, ServiceRes.FilePurpose) } } ; FilePurpose = (FilePurposeEnum)tempInt; FileDescription = fc["FileDescription"]; if (string.IsNullOrWhiteSpace(FileDescription)) { return new TVFileModel() { Error = string.Format(ServiceRes._IsRequired, ServiceRes.FileDescription) } } ; if (fc["KeepFileName"] == null) { KeepFileName = false; } if (!KeepFileName) { SaveAsFileName = fc["SaveAsFileName"]; if (string.IsNullOrWhiteSpace(SaveAsFileName)) { return new TVFileModel() { Error = string.Format(ServiceRes._IsRequired, ServiceRes.SaveAsFileName) } } ; } if (fc["FromWater"] != null) { if (string.IsNullOrWhiteSpace(fc["FromWater"])) { FromWater = null; } else { FromWater = true; } } List <string> AllowableExt = _TVFileService.GetAllowableExt(); TVFileModel tvFileModelRet = new TVFileModel(); using (TransactionScope ts = new TransactionScope()) { string FileName = ""; if (Request.Files.Count != 1) { return(_TVFileService.ReturnError(ServiceRes.CanOnlyLoadOneFileAtATime)); } HttpPostedFileBase hpf = null; foreach (string file in Request.Files) { hpf = Request.Files[file]; } if (hpf == null) { return(_TVFileService.ReturnError(ServiceRes.PleaseSelectAFileToUpload)); } FileName = hpf.FileName; FileInfo fi = new FileInfo(FileName); if (!AllowableExt.Contains(fi.Extension.ToLower())) { string AllowableExtText = ""; foreach (string s in AllowableExt) { AllowableExtText += s + " "; } return(_TVFileService.ReturnError(string.Format(ServiceRes.PleaseSelectAFileOfType_, AllowableExtText))); } string ServerFileName = ""; if (FileName.Contains(@"\")) { ServerFileName = FileName.Substring(FileName.LastIndexOf(@"\") + 1); } else { ServerFileName = FileName; } if (!KeepFileName) { ServerFileName = SaveAsFileName + fi.Extension; } string ServerFilePath = ""; TVItemModel tvItemModelParent = new TVItemModel(); if (FilePurpose == FilePurposeEnum.Template) { tvItemModelParent = _TVItemService.GetRootTVItemModelDB(); if (!string.IsNullOrEmpty(tvItemModelParent.Error)) { return(_TVFileService.ReturnError(tvItemModelParent.Error)); } } else { tvItemModelParent = _TVFileService._TVItemService.GetTVItemModelWithTVItemIDDB(ParentTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelParent.Error)) { return(_TVFileService.ReturnError(tvItemModelParent.Error)); } } TVItemModel tvItemModelExist = _TVFileService._TVItemService.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelParent.TVItemID, ServerFileName, TVTypeEnum.File); if (string.IsNullOrEmpty(tvItemModelExist.Error)) { return(_TVFileService.ReturnError(string.Format(ServiceRes._AlreadyExists, ServerFileName))); } TVItemModel tvItemModelTVFileRet = _TVFileService._TVItemService.PostAddChildTVItemDB(tvItemModelParent.TVItemID, ServerFileName, TVTypeEnum.File); if (!string.IsNullOrEmpty(tvItemModelTVFileRet.Error)) { return(_TVFileService.ReturnError(tvItemModelTVFileRet.Error)); } ServerFilePath = _TVFileService.GetServerFilePath(tvItemModelParent.TVItemID); int FileLength = hpf.ContentLength; DirectoryInfo di = new DirectoryInfo(ServerFilePath); if (!di.Exists) { di.Create(); } fi = new FileInfo(ServerFilePath + ServerFileName); if (fi.Exists) { return(_TVFileService.ReturnError(string.Format(ServiceRes.File_AlreadyExist, ServerFileName))); } hpf.SaveAs(fi.FullName); FileTypeEnum fileType = _TVFileService.GetFileType(fi.Extension.ToUpper()); if (FilePurpose == FilePurposeEnum.Template) { //if (!(fileType == FileTypeEnum.CSV || fileType == FileTypeEnum.XLSX || fileType == FileTypeEnum.DOCX || fileType == FileTypeEnum.KML)) //{ // DeleteFileFromServer(fi); // return _TVFileService.ReturnError(string.Format(ServiceRes.WhenUploadingTemplateOnlyFileTypes_AreAllowed, ".csv, .docx, .xlsx, .kml")); //} if (!(fileType == FileTypeEnum.CSV || fileType == FileTypeEnum.DOCX || fileType == FileTypeEnum.KML || fileType == FileTypeEnum.XLSX)) { DeleteFileFromServer(fi); return(_TVFileService.ReturnError(string.Format(ServiceRes.WhenUploadingTemplateOnlyFileTypes_AreAllowed, ".csv, .docx, .xmlx and .kml") + " ... for now.")); } } TVFileModel tvFileModelNew = new TVFileModel() { TVFileTVItemID = tvItemModelTVFileRet.TVItemID, FilePurpose = FilePurpose, FileDescription = FileDescription, FileType = fileType, FileSize_kb = Math.Max(hpf.ContentLength / 1024, 1), FileInfo = "Uploaded file", FileCreatedDate_UTC = DateTime.Now, FromWater = FromWater, ClientFilePath = FileName, ServerFileName = ServerFileName, ServerFilePath = ServerFilePath, Language = Language, Year = Year, }; TVFile tvFileExist = _TVFileService.GetTVFileExistDB(tvFileModelNew); if (tvFileExist != null) { DeleteFileFromServer(fi); return(_TVFileService.ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.TVFile))); } tvFileModelRet = _TVFileService.PostAddTVFileDB(tvFileModelNew); if (!string.IsNullOrWhiteSpace(tvFileModelRet.Error)) { DeleteFileFromServer(fi); return(_TVFileService.ReturnError(tvFileModelRet.Error)); } if (FilePurpose == FilePurposeEnum.Template) { tvItemModelParent = _TVFileService._TVItemService.GetTVItemModelWithTVItemIDDB(ParentTVItemID); if (!string.IsNullOrWhiteSpace(tvItemModelParent.Error)) { return(_TVFileService.ReturnError(tvItemModelParent.Error)); } DocTemplateModel docTemplateModelNew = new DocTemplateModel() { TVType = tvItemModelParent.TVType, TVFileTVItemID = tvFileModelRet.TVFileTVItemID, FileName = ServerFileName, }; DocTemplateModel docTemplateModelRet = _DocTemplateService.PostAddDocTemplateDB(docTemplateModelNew); if (!string.IsNullOrWhiteSpace(docTemplateModelRet.Error)) { DeleteFileFromServer(fi); return(_TVFileService.ReturnError(docTemplateModelRet.Error)); } //bool IsTrue = true; //if (IsTrue) //{ // DeleteFileFromServer(fi); // return _TVFileService.ReturnError("Should parse the File to check if the first ||| tag has the right TVType"); //} } ts.Complete(); } return(tvFileModelRet); }