Esempio n. 1
0
        protected void DownloadFile(object sender, EventArgs e)
        {
            LinkButton lnkDownloadAttachment = (LinkButton)sender;

            int id = Convert.ToInt32(lnkDownloadAttachment.CommandArgument);

            var accept = dbContext.tblAttachments.Where(x => x.id == id).FirstOrDefault();

            if (accept != null)
            {
                accept.IsCheckerReviewed = true;

                accept.datecreated = DateTime.Now;

                dbContext.Entry(accept).State = EntityState.Modified;

                dbContext.SaveChanges();
            }

            tblAttachment empdata = new tblAttachment();

            var selectQuery = dbContext.tblAttachments.Where(x => x.id == id);

            foreach (var item in selectQuery)
            {
                tblAttachment myData = item as tblAttachment;

                DownloadFileFromDatabase(myData.attachmentfile, myData.attachmentname, myData.contenttype);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// SaveKnowledgeBase() method is used to save knowledgebase data
        /// </summary>
        /// <param name="KnowledgeBase"></param>
        public void SaveKnowledgeBase(KnowledgeBase knowledgeBase)
        {
            using (var dbContextTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    tblKnowledgeBase objKnowledgeBase = null;
                    objKnowledgeBase = new tblKnowledgeBase()
                    {
                        Title          = knowledgeBase.Title,
                        Text           = knowledgeBase.Text,
                        DistrictId     = knowledgeBase.DistrictId,
                        RoleId         = knowledgeBase.RoleId,
                        CreateDatetime = knowledgeBase.CreatedDateTime,
                    };
                    _db.tblKnowledgeBases.Add(objKnowledgeBase);
                    _db.SaveChanges();
                    tblAttachment objAttachment = null;

                    if (knowledgeBase.FileDetails != null)
                    {
                        foreach (var file in knowledgeBase.FileDetails)
                        {
                            objAttachment = new tblAttachment()
                            {
                                CreatedDate      = knowledgeBase.CreatedDateTime,
                                CreatedUserId    = knowledgeBase.CreatedUserId,
                                FileName         = file.PhysicalFileName,
                                OriginalFileName = file.OriginalFileName,
                                FileExtension    = file.FileExtension
                            };

                            _db.tblAttachments.Add(objAttachment);
                            _db.SaveChanges();

                            tblKnowledgeBaseAttachment objKnowledgeBaseAttachment = null;
                            objKnowledgeBaseAttachment = new tblKnowledgeBaseAttachment()
                            {
                                AttachmentId    = objAttachment.AttachmentId,
                                KnowledgeBaseId = objKnowledgeBase.KnowledgeBaseId,
                                CreatedDate     = knowledgeBase.CreatedDateTime,
                                CreatedUserId   = knowledgeBase.CreatedUserId
                            };
                            _db.tblKnowledgeBaseAttachments.Add(objKnowledgeBaseAttachment);
                            _db.SaveChanges();
                        }
                    }
                    dbContextTransaction.Commit();
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw ex;
                }
            }
        }
        protected void DownloadFile(object sender, EventArgs e)
        {
            LinkButton lnkDownloadAttachment = (LinkButton)sender;

            int id = Convert.ToInt32(lnkDownloadAttachment.CommandArgument);

            tblAttachment empdata = new tblAttachment();

            var selectQuery = dbContext.tblAttachments.Where(x => x.id == id);

            foreach (var item in selectQuery)
            {
                tblAttachment myData = item as tblAttachment;

                DownloadFileFromDatabase(myData.attachmentfile, myData.attachmentname, myData.contenttype);
            }
        }
Esempio n. 4
0
        protected void UploadMultipleFileExisting(object sender, EventArgs e)
        {
            if (uploadFile.UploadedFiles.Count == 0)
            {
                Show("Select File First");
            }
            else
            {
                //Convert File To Base64String Before Saving to Database

                string fileext = string.Empty;

                foreach (UploadedFile file in uploadFile.UploadedFiles)
                {
                    byte[] bytes = new byte[file.ContentLength];

                    file.InputStream.Read(bytes, 0, bytes.Length);

                    filename = file.GetName().Replace(",", "_").Replace(" ", "_");

                    //filetype = file.ContentType;

                    fileext = Path.GetExtension(filename);

                    if (fileext == ".pdf")
                    {
                        filetype = "application/pdf";
                    }
                    else if (fileext == ".xls")
                    {
                        filetype = "application/vnd.ms-excel";
                    }
                    else if (fileext == ".xlsx")
                    {
                        filetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    }
                    else if (fileext.ToLower() == ".pptx")
                    {
                        filetype = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                    }
                    else if (fileext.ToLower() == ".ppt")
                    {
                        filetype = "application/vnd.ms-powerpoint";
                    }
                    else if (fileext.ToLower() == ".docx")
                    {
                        filetype = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    }
                    else if (fileext.ToLower() == ".doc")
                    {
                        filetype = "application/msword";
                    }
                    else if (fileext.ToLower() == ".jpeg" || fileext == ".jpg")
                    {
                        filetype = "image/jpeg";
                    }

                    else if (fileext.ToLower() == ".png")
                    {
                        filetype = "image/png";
                    }

                    Response.Charset = string.Empty;

                    string code = Session["RCode"].ToString().Trim();

                    //var a = dbContext.tblAttachments.Where(x => x.attachmentname == filename && x.jr_code == code
                    //&& x.typeofattachment == "Admin").FirstOrDefault();

                    //if(a != null)
                    //{
                    tblAttachment tbl = new tblAttachment()
                    {
                        attachmentfile     = Convert.ToBase64String(bytes, 0, bytes.Length),
                        attachmentname     = filename,
                        contenttype        = filetype,
                        jr_code            = code,//Session["RCode"].ToString().Trim(),
                        typeofattachment   = "Admin",
                        IsChecked          = false,
                        IsPrepared         = false,
                        IsApproved         = false,
                        IsCheckerReviewed  = false,
                        IsApproverReviewed = false,
                        issubmitted        = true,
                        datecreated        = DateTime.Now
                    };

                    dbContext.tblAttachments.Add(tbl);

                    dbContext.SaveChanges();
                    //}
                }

                gridAttachment2.Rebind();
            }
        }
        /// <summary>
        /// SaveKnowledgeBase() method is used to save knowledgebase data
        /// </summary>
        /// <param name="KnowledgeBase"></param>
        public void SaveKnowledgeBase(KnowledgeBase knowledgeBase)
        {

            using (var dbContextTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    tblKnowledgeBase objKnowledgeBase = null;
                    objKnowledgeBase = new tblKnowledgeBase()
                                        {
                                            Title = knowledgeBase.Title,
                                            Text = knowledgeBase.Text,
                                            DistrictId = knowledgeBase.DistrictId,
                                            RoleId = knowledgeBase.RoleId,
                                            CreateDatetime = knowledgeBase.CreatedDateTime,
                                        };
                    _db.tblKnowledgeBases.Add(objKnowledgeBase);
                    _db.SaveChanges();
                    tblAttachment objAttachment = null;

                    if (knowledgeBase.FileDetails != null)
                    {
                        foreach (var file in knowledgeBase.FileDetails)
                        {
                            objAttachment = new tblAttachment()
                            {
                                CreatedDate = knowledgeBase.CreatedDateTime,
                                CreatedUserId = knowledgeBase.CreatedUserId,
                                FileName = file.PhysicalFileName,
                                OriginalFileName = file.OriginalFileName,
                                FileExtension = file.FileExtension
                            };

                            _db.tblAttachments.Add(objAttachment);
                            _db.SaveChanges();

                            tblKnowledgeBaseAttachment objKnowledgeBaseAttachment = null;
                            objKnowledgeBaseAttachment = new tblKnowledgeBaseAttachment()
                                                        {
                                                            AttachmentId = objAttachment.AttachmentId,
                                                            KnowledgeBaseId = objKnowledgeBase.KnowledgeBaseId,
                                                            CreatedDate = knowledgeBase.CreatedDateTime,
                                                            CreatedUserId = knowledgeBase.CreatedUserId
                                                        };
                            _db.tblKnowledgeBaseAttachments.Add(objKnowledgeBaseAttachment);
                            _db.SaveChanges();
                        }
                    }
                    dbContextTransaction.Commit();
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw ex;
                }
            }
        }