public AttachmentsDTO GetAttachmentByID(int AttachmentID) { using (var uow = new UnitOfWork()) { try { AttachmentsDTO dto = new AttachmentsDTO(); dto = uow.Attachments.GetAttachmentByID(AttachmentID); if (dto != null) { return(dto); } else { return(null); } } catch (Exception ex) { ex.Data.Add("GetAttachmentByID", "An error occurred while trying to Get Attachment By ID Record - BLL"); uow.Rollback(); Tracer.Error(ex); return(null); } } }
public bool AddAttachment(AttachmentsDTO dto) { using (var uow = new UnitOfWork()) { try { var isAdded = uow.Attachments.AddAttachment(dto); if (isAdded == true) { return(true); } else { return(false); } } catch (Exception ex) { ex.Data.Add("AddQuestion", "An error occurred while trying to create Question Record - BLL"); uow.Rollback(); Tracer.Error(ex); return(false); } } }
public bool AddAttachment(AttachmentsDTO dto) { var savedAttachment = new Attachment() { caption = dto.Caption, contentType = dto.ContentType, data = dto.Data, fileName = dto.FileName, SourceDataType = dto.SourceDataTypeId, AttachmentName = dto.FileName, }; Create(savedAttachment); _uow.Save(); bool isSaved = false; if (savedAttachment.AttachmentID > 0) { isSaved = true; } else { isSaved = false; } return(isSaved); }
public bool AddAttachments(AttachmentsDTO dto) { bool saved = _AttachmentsBusinessLogic.AddAttachment(dto); if (saved == true) { return(true); } else { return(false); } }
public AttachmentsDTO GetAttachmentByID(int AttachmentID) { AttachmentsDTO dto = new AttachmentsDTO(); var attachment = GetQuerable(x => x.AttachmentID == AttachmentID).FirstOrDefault(); dto.Id = attachment.AttachmentID; dto.SourceDataTypeId = attachment.SourceDataType; dto.Data = attachment.data; dto.FileName = attachment.fileName; dto.ContentType = attachment.contentType; dto.AttachmentId = attachment.AttachmentID; dto.AttachmentID = attachment.AttachmentID; dto.Caption = attachment.caption; return(dto); }
public ActionResult Index(SheetViewModel sheet) { string filePath = string.Empty; if (sheet.SourceDataTypeId > 0) { foreach (string upload in Request.Files) { if (Request.Files[upload].FileName != "") { filePath = Path.GetFileName(Request.Files[upload].FileName); string fileName = Request.Files[upload].FileName; string contentType = Request.Files[upload].ContentType; long fileLength = Request.Files[upload].InputStream.Length; byte[] fileContent = new byte[fileLength]; using (MemoryStream memoryStream = new MemoryStream()) { Request.Files[upload].InputStream.CopyTo(memoryStream); fileContent = memoryStream.ToArray(); } AttachmentsDTO attachmentData = new AttachmentsDTO(); string path = Server.MapPath("~/Uploads/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } filePath = path + Path.GetFileName(fileName); string extension = Path.GetExtension(fileName); Request.Files[upload].SaveAs(filePath); //Read the contents of CSV file. string csvData = System.IO.File.ReadAllText(filePath); attachmentData.Data = fileContent; attachmentData.ContentType = contentType; attachmentData.FileNameWithExtension = fileName; attachmentData.FileName = fileName; switch (sheet.SourceDataTypeId) { case (int)SourceDataType.Datausage: attachmentData.SourceDataTypeId = (int)SourceDataType.Datausage; break; case (int)SourceDataType.Linereports: attachmentData.SourceDataTypeId = (int)SourceDataType.Linereports; break; case (int)SourceDataType.Linestatus: attachmentData.SourceDataTypeId = (int)SourceDataType.Linestatus; break; default: break; } bool isAdded = AddCSVFileData(csvData, attachmentData.SourceDataTypeId); if (AddAttachments(attachmentData) == true) { TempData["Success"] = jepco.CommonLayer.App_LocalResources.Resource.Success; return(RedirectToAction("Index")); } else { TempData["Error"] = jepco.CommonLayer.App_LocalResources.Resource.Error; return(RedirectToAction("Index")); } } } } return(View()); }