/// <summary> /// Creates a new Attachment record using async /// </summary> public static async Task<int> CreateAsync(AttachmentDO DO) { SqlParameter _AttachmentTypeID = new SqlParameter("AttachmentTypeID", SqlDbType.Int); SqlParameter _PermitKey = new SqlParameter("PermitKey", SqlDbType.Int); SqlParameter _DateUploaded = new SqlParameter("DateUploaded", SqlDbType.DateTime); SqlParameter _UserToken = new SqlParameter("UserToken", SqlDbType.VarChar); SqlParameter _FileSize = new SqlParameter("FileSize", SqlDbType.Int); SqlParameter _Description = new SqlParameter("Description", SqlDbType.VarChar); SqlParameter _MimeType = new SqlParameter("MimeType", SqlDbType.VarChar); SqlParameter _FileName = new SqlParameter("FileName", SqlDbType.VarChar); SqlParameter _TOCID = new SqlParameter("TOCID", SqlDbType.Int); SqlParameter _TOCLayerID = new SqlParameter("TOCLayerID", SqlDbType.Int); SqlParameter _ParentAttachmentID = new SqlParameter("ParentAttachmentID", SqlDbType.Int); SqlParameter _IsACopy = new SqlParameter("IsACopy", SqlDbType.Bit); _AttachmentTypeID.Value = DO.AttachmentTypeID; _PermitKey.Value = DO.PermitKey; _DateUploaded.Value = DO.DateUploaded; _UserToken.Value = DO.UserToken; _FileSize.Value = DO.FileSize; _Description.Value = DO.Description; _MimeType.Value = DO.MimeType; _FileName.Value = DO.FileName; _TOCID.Value = DO.TOCID; _TOCLayerID.Value = DO.TOCLayerID; _ParentAttachmentID.Value = DO.ParentAttachmentID; _IsACopy.Value = DO.IsACopy; SqlParameter[] _params = new SqlParameter[] { _AttachmentTypeID, _PermitKey, _DateUploaded, _UserToken, _FileSize, _Description, _MimeType, _FileName, _TOCID, _TOCLayerID, _ParentAttachmentID, _IsACopy }; string pid = ConfigurationManager.AppSettings["ePermitDAL"]; return await DataCommon.ExecuteScalarAsync("[dbo].[Attachment_Insert]", _params, pid); }
/// <summary> /// Selects Attachment records by TOCID /// </summary> public static async Task<AttachmentDO[]> GetByTOCIDAsync(Int32 TOCID) { SqlParameter _TOCID = new SqlParameter("TOCID", SqlDbType.Int); _TOCID.Value = TOCID; SqlParameter[] _params = new SqlParameter[] { _TOCID }; string pid = ConfigurationManager.AppSettings["ePermitDAL"]; SafeReader sr = await DataCommon.ExecuteSafeReaderAsync("[dbo].[Attachment_GetByTOCID]", _params, pid); List<AttachmentDO> objs = new List<AttachmentDO>(); while(sr.Read()) { AttachmentDO obj = new AttachmentDO(); obj.AttachmentID = sr.GetInt32(sr.GetOrdinal("AttachmentID")); obj.DateUploaded = sr.GetDateTime(sr.GetOrdinal("DateUploaded")); obj.UserToken = sr.GetString(sr.GetOrdinal("UserToken")); obj.FileSize = sr.GetInt32(sr.GetOrdinal("FileSize")); obj.Description = sr.GetString(sr.GetOrdinal("Description")); if (sr.IsDBNull(sr.GetOrdinal("AttachmentTypeID"))) { obj.AttachmentTypeID = null; } else { obj.AttachmentTypeID = sr.GetInt32(sr.GetOrdinal("AttachmentTypeID")); } if (sr.IsDBNull(sr.GetOrdinal("PermitKey"))) { obj.PermitKey = null; } else { obj.PermitKey = sr.GetInt32(sr.GetOrdinal("PermitKey")); } if (sr.IsDBNull(sr.GetOrdinal("MimeType"))) { obj.MimeType = null; } else { obj.MimeType = sr.GetString(sr.GetOrdinal("MimeType")); } if (sr.IsDBNull(sr.GetOrdinal("FileName"))) { obj.FileName = null; } else { obj.FileName = sr.GetString(sr.GetOrdinal("FileName")); } if (sr.IsDBNull(sr.GetOrdinal("TOCID"))) { obj.TOCID = null; } else { obj.TOCID = sr.GetInt32(sr.GetOrdinal("TOCID")); } if (sr.IsDBNull(sr.GetOrdinal("TOCLayerID"))) { obj.TOCLayerID = null; } else { obj.TOCLayerID = sr.GetInt32(sr.GetOrdinal("TOCLayerID")); } if (sr.IsDBNull(sr.GetOrdinal("ParentAttachmentID"))) { obj.ParentAttachmentID = null; } else { obj.ParentAttachmentID = sr.GetInt32(sr.GetOrdinal("ParentAttachmentID")); } if (sr.IsDBNull(sr.GetOrdinal("IsACopy"))) { obj.IsACopy = null; } else { obj.IsACopy = sr.GetBoolean(sr.GetOrdinal("IsACopy")); } objs.Add(obj); } return objs.ToArray(); }
/// <summary> /// Deletes a Attachment record /// </summary> public static async Task<int> DeleteAsync(AttachmentDO DO) { SqlParameter _AttachmentID = new SqlParameter("AttachmentID", SqlDbType.Int); _AttachmentID.Value = DO.AttachmentID; SqlParameter[] _params = new SqlParameter[] { _AttachmentID }; string pid = ConfigurationManager.AppSettings["ePermitDAL"]; return await DataCommon.ExecuteScalarAsync("[dbo].[Attachment_Delete]", _params, pid); }
/// <summary> /// Create a new view model instance from a data object /// </summary> /// <param name="dataObject"></param> public AttachmentVM(AttachmentDO dataObject) : base() { CopyDOProperties(dataObject); }
/// <summary> /// copies properties from the data object to this derived instance /// </summary> /// <param name="dataObject"></param> private void CopyDOProperties(AttachmentDO dataObject) { this.IsACopy = dataObject.IsACopy; this.PermitKey = dataObject.PermitKey; this.AttachmentID = dataObject.AttachmentID; this.AttachmentTypeID = dataObject.AttachmentTypeID; this.DateUploaded = dataObject.DateUploaded; this.Description = dataObject.Description; this.FileName = dataObject.FileName; this.FileSize = dataObject.FileSize; this.MimeType = dataObject.MimeType; this.ParentAttachmentID = dataObject.ParentAttachmentID; this.TOCID = dataObject.TOCID; this.TOCLayerID = dataObject.TOCLayerID; this.UserToken = dataObject.UserToken; }
AttachmentDO SaveAttachment(int PermitKey, int AttachmentTypeId) { HttpPostedFileBase File = Request.Files["File"]; // build attachment meta data AttachmentDO attachment = new AttachmentDO() { IsACopy = false, ParentAttachmentID = null, AttachmentTypeID = AttachmentTypeId, DateUploaded = DateTime.Now, Description = File.FileName, FileSize = File.ContentLength, MimeType = File.ContentType, PermitKey = PermitKey, TOCID = null, TOCLayerID = null, UserToken = myCoalUser.UserToken }; // read content from stream byte[] content = new byte[File.ContentLength]; File.InputStream.Read(content, 0, (int)File.ContentLength); // Save it attachment.AttachmentID = AttachmentBLL.Save(attachment, content, DirectoryMapping.AttachmentContentFolder); return attachment; }
/// <summary> /// Saves an attachment for a help screen template /// </summary> /// <param name="PermitKey"></param> /// <param name="TOCID"></param> /// <returns></returns> public ActionResult UploadTemplate(int PermitKey, int TOCID) { try { HttpPostedFileBase File = Request.Files["File"]; // build attachment meta data AttachmentDO attachment = new AttachmentDO() { IsACopy = false, ParentAttachmentID = null, AttachmentTypeID = null, DateUploaded = DateTime.Now, Description = File.FileName, FileName = "database", FileSize = File.ContentLength, MimeType = File.ContentType, PermitKey = PermitKey, TOCID = TOCID, TOCLayerID = null, UserToken = myCoalUser.UserToken }; // read content from stream byte[] content = new byte[File.ContentLength]; File.InputStream.Read(content, 0, (int)File.ContentLength); // Save it AttachmentBLL.Save(attachment, content, DirectoryMapping.AttachmentContentFolder); AjaxResult result = new AjaxResult(AjaxResult.AjaxStatus.OK, "Attachment Uploaded"); return Json(result); } catch (Exception ex) { AjaxResult result = new AjaxResult(AjaxResult.AjaxStatus.ERROR, ex.Message); return Json(result); } }