public bool SaveOrUpdateOMRecords(OMNITURE_DATA omData, string fweek) { bool isFileSaved = false; try { using (var ctx = new TODEntities()) { DateTime currDate = TodDateUtils.GetCurrentTimeInIST(); string fiscalweek = TodDateUtils.GetWeekOfYearFor(TodDateUtils.GetCurrentTimeInIST()); DateTime ceStartDate = currDate.AddDays(-7).Date; DateTime ceEndDate = currDate.AddDays(-1).Date; omData.FW_ID = fweek; omData.FW_START_DATE = ceStartDate; omData.FW_END_DATE = ceEndDate; omData.REP_GEN_DATE = currDate; omData.OMNITURE_STATUS = "Success"; ctx.OMNITURE_DATA.Attach(omData); ctx.Entry <OMNITURE_DATA>(omData).State = omData.SEQUENCE_ID == 0 ? EntityState.Added : EntityState.Unchanged; ctx.SaveChanges(); } isFileSaved = true; } catch (Exception e) { log.Info(e.Message); isFileSaved = false; } return(isFileSaved); }
public JsonResult UploadMultiple(HttpPostedFileBase[] uploadedFiles, string fweek) { bool success = true; OMNITURE_DATA omData = new OMNITURE_DATA(); tODDataService = new TODDataService(); for (var i = 0; i < uploadedFiles.Length; i++) { var uploadedFile = uploadedFiles[i]; if (uploadedFile != null && uploadedFile.ContentLength > 0) { byte[] FileByteArray = new byte[uploadedFile.ContentLength]; uploadedFile.InputStream.Read(FileByteArray, 0, uploadedFile.ContentLength); //save the file to database omData = tODDataService.AppendFileData(omData, uploadedFile, fweek); } } success = tODDataService.SaveOrUpdateOMRecords(omData, fweek); if (success) { log.Info("Files successfully uploaded to database."); ViewData["UploadStatus"] = Json(new { statusCode = 200, status = "Files Uploaded Successfully" }, JsonRequestBehavior.AllowGet); } else { log.Info("Files uploading to database failed."); ViewData["UploadStatus"] = Json(new { statusCode = 400, status = "Bad Request! Upload Failed", file = string.Empty }, JsonRequestBehavior.AllowGet); } return(Json(ViewData)); }
public OMNITURE_DATA AppendFileData(OMNITURE_DATA omData, HttpPostedFileBase uploadedFile, string fweek) { bool isFileSaved = false; try { /*var qresult = (from om in ctx.OMNITURE_DATA * join fd in ctx.FW_CALENDAR * on om.FW_ID equals fd.Fiscal_Week * where om.FW_ID == fweek * select om).ToList(); * List<OMNITURE_DATA> omDataList = qresult.Distinct().ToList(); * * if(omDataList.Count == 0) * { * log.Info("Omniture Reports Records not found for the Week : (" + fweek + ")"); * } */ byte[] FileByteArray = new byte[uploadedFile.ContentLength]; uploadedFile.InputStream.Read(FileByteArray, 0, uploadedFile.ContentLength); string FileName = uploadedFile.FileName; if (FileName.Contains("c58") || FileName.Contains("TOD")) // TOD Report file { omData.TOD_REPORT = FileByteArray; } else if (FileName.Contains("ProductCD")) // Product Code File { omData.PRODUCT_CODE = FileByteArray; } else if (FileName.Contains("Language")) // Language Report { omData.LANGUAGE_REPORT = FileByteArray; } else if (FileName.Contains("Product Name")) // product Name Report file { omData.PRODUCT_NAME = FileByteArray; } else if (FileName.Contains("Publication ID")) // publication id Report File { omData.PUBLICATION_ID = FileByteArray; } else if (FileName.Contains("GUID")) // topic guid report file { omData.TOPIC_GUID = FileByteArray; } else if (FileName.Contains("Topic Title")) // topic title report file { omData.TOPIC_TITLE = FileByteArray; } else if (FileName.Contains("Manual Title")) { omData.MANUAL_TITLE = FileByteArray; } isFileSaved = true; } catch (Exception e) { log.Info(e.Message); isFileSaved = false; } return(omData); }