Beispiel #1
0
        private void LoadAttachment(long iD)
        {
            try
            {
                DataTable FilesDT = new System.Data.DataTable();
                FilesDT.Columns.Add("FileName");
                FilesDT.Columns.Add("AttachmentPath");
                FilesDT.Columns.Add("Category");

                ClientAttachment attach = new ClientAttachment();
                attach.Where.ClientID.Value = iD;
                attach.Query.AddOrderBy(ClientAttachment.ColumnNames.Type, MyGeneration.dOOdads.WhereParameter.Dir.ASC);
                if (attach.Query.Load())
                {
                    do
                    {
                        DataRow dr = FilesDT.NewRow();
                        dr["FileName"]       = attach.FileName;
                        dr["AttachmentPath"] = attach.AttachmentPath;
                        dr["Category"]       = attach.Type;



                        FilesDT.Rows.Add(dr);
                    }while (attach.MoveNext());

                    AttachmentsBC.BindAttachments(FilesDT.DefaultView);
                }
            }
            catch (Exception ex)
            {
                LBL_MSG.Visible = true;
                LBL_MSG.Text    = "LoadAttachment:" + ex.Message;
            }
        }
        public ActionResult UploadClientDocument(ClientAttachment model, HttpPostedFileBase document)
        {
            if (document != null)
            {
                string fileExtension = Path.GetExtension(document.FileName);
                string doc           = Guid.NewGuid().ToString().Replace("-", "").ToLower().Substring(2, 8) + fileExtension;
                string path          = Path.Combine(
                    Server.MapPath("~/ClientDocuments"), doc);
                // file is uploaded
                document.SaveAs(path);
                var anUser = (ViewUser)Session["User"];
                model.UploadedByUserId = anUser.UserId;
                model.FilePath         = "ClientDocuments/" + doc;
                model.FileExtension    = fileExtension;
                bool result = _iClientManager.UploadClientDocument(model);
                if (result)
                {
                    ViewBag.Message = "<p style='coler:green'> Uploaded Successfully!</p>";
                }
            }
            else
            {
                ViewBag.Message = "<p style='coler:red'> File upload failed</p>";
            }

            return(View());
        }
 public int UploadClientDocument(ClientAttachment clientAttachment)
 {
     try
     {
         CommandObj.CommandText = "UDSP_UploadClientDocument";
         CommandObj.CommandType = CommandType.StoredProcedure;
         CommandObj.Parameters.AddWithValue("@ClientId", clientAttachment.ClientId);
         CommandObj.Parameters.AddWithValue("@AttachmentName", clientAttachment.AttachmentName);
         CommandObj.Parameters.AddWithValue("@UploadedByUserId", clientAttachment.UploadedByUserId);
         CommandObj.Parameters.AddWithValue("@FileExtension", clientAttachment.FileExtension);
         CommandObj.Parameters.AddWithValue("@FilePath", clientAttachment.FilePath);
         CommandObj.Parameters.Add("@RowAffected", SqlDbType.Int);
         CommandObj.Parameters["@RowAffected"].Direction = ParameterDirection.Output;
         ConnectionObj.Open();
         CommandObj.ExecuteNonQuery();
         int rowAffected = Convert.ToInt32(CommandObj.Parameters["@RowAffected"].Value);
         return(rowAffected);
     }
     catch (SqlException sqlException)
     {
         throw new Exception("Could not upload client document due to sql Exception", sqlException);
     }
     catch (Exception exception)
     {
         throw new Exception("Could not upload client document", exception);
     }
     finally
     {
         ConnectionObj.Close();
         CommandObj.Dispose();
         CommandObj.Parameters.Clear();
     }
 }
        public bool UploadClientDocument(ClientAttachment clientAttachment)
        {
            int rowAffected = _iClientGateway.UploadClientDocument(clientAttachment);

            return(rowAffected > 0);
        }