public string createAttachment(string fileStore, string type, string name, FileUpload fileUpload, int id) { int nextVersion = getNextVersion(fileStore, type, id); string nextPath = fileStore + "\\" + type + "_" + id.ToString() + "\\V" + nextVersion.ToString(); try { fileUpload.PostedFile.SaveAs(nextPath + "\\" + fileUpload.FileName); } catch (Exception ex) { Logger.logmessage(classobject, "uploadfile", ex.Message + ex.StackTrace); } Su_Attachment_Version atv = new Su_Attachment_Version(); Su_Attachment at = new Su_Attachment(); at.name = name; at.path = nextPath + "\\" + fileUpload.FileName; at.mime_type = fileUpload.PostedFile.ContentType; dataContext.Su_Attachments.InsertOnSubmit(at); try { dataContext.SubmitChanges(); } catch (Exception ex) { Logger.logmessage(classobject, "uploadfile Su_Attachment submit", ex.Message + ex.StackTrace); } if (ATTACHMENT_TYPE_VB.Equals(type)) { Su_VanBan_Attachment vAt = new Su_VanBan_Attachment(); vAt.attachment_id = at.id; vAt.vanban_id = id; dataContext.Su_VanBan_Attachments.InsertOnSubmit(vAt); try { dataContext.SubmitChanges(); } catch (Exception ex) { Logger.logmessage(classobject, "uploadfile Su_VanBan_Attachment submit", ex.Message + ex.StackTrace); } } else if (ATTACHMENT_TYPE_HS.Equals(type)) { Su_HoSo_Attachment hAt = new Su_HoSo_Attachment(); hAt.attachment_id = at.id; hAt.id_hoso = id; dataContext.Su_HoSo_Attachments.InsertOnSubmit(hAt); try { dataContext.SubmitChanges(); } catch (Exception ex) { Logger.logmessage(classobject, "uploadfile Su_HoSo_Attachment submit", ex.Message + ex.StackTrace); } } return(nextPath + "\\" + fileUpload.FileName); }
public void deleteAttachmentFromHoSo(int hid, int attachId) { Su_HoSo_Attachment obj = dataContext.Su_HoSo_Attachments.Where(p => p.id_hoso == hid && p.attachment_id == attachId).FirstOrDefault(); if (obj != null) { dataContext.Su_HoSo_Attachments.DeleteOnSubmit(obj); dataContext.SubmitChanges(); } }