public GeneralInformationModel GetGeneralInformationDetail(int GeneralInformationId)
 {
     if (ClientSessionData.UserClientId != 0)
     {
         GeneralInformationModel generalInformationModel = new GeneralInformationModel();
         try
         {
             var GeneralInformation = _context.tblGeneralInformations.Where(x => x.GeneralInformationId == GeneralInformationId && x.Status == 1).FirstOrDefault();
             if (GeneralInformation != null)
             {
                 generalInformationModel.GeneralInformationId = GeneralInformation.GeneralInformationId;
                 generalInformationModel.Title            = GeneralInformation.Title;
                 generalInformationModel.Description      = GeneralInformation.Description;
                 generalInformationModel.UploadFile       = GeneralInformation.UploadFile;
                 generalInformationModel.OldUploadFile    = GeneralInformation.UploadFile;
                 generalInformationModel.ActualUploadFile = GeneralInformation.ActualUploadFile;
                 generalInformationModel.CreatedOn        = GeneralInformation.CreatedOn != null?GeneralInformation.CreatedOn.Value.ToString("dd MMM, yyyy") : "N/A";
             }
         }
         catch
         {
         }
         return(generalInformationModel);
     }
     else
     {
         return(null);
     }
 }
Example #2
0
        public FileResult DownloadUploadedFile(int GeneralInformationId)
        {
            string FilePath = "resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/generalinformation/";
            GeneralInformationModel model = noticeBoardHelper.GetGeneralInformationDetail(GeneralInformationId);
            string path = AwsS3Bucket.DownloadObject2(model.UploadFile, FilePath);

            return(File(Path.Combine(Server.MapPath(path)), MimeMapping.GetMimeMapping(model.UploadFile), System.IO.Path.GetFileName(path)));
        }
        public int AddUpdateGeneralInformation(GeneralInformationModel generalInformationModel)
        {
            int result = 0;

            try
            {
                tblGeneralInformation tblGeneralInformationDb = new tblGeneralInformation();
                tblGeneralInformationDb.Title            = generalInformationModel.Title;
                tblGeneralInformationDb.Description      = generalInformationModel.Description;
                tblGeneralInformationDb.UploadFile       = generalInformationModel.UploadFile;
                tblGeneralInformationDb.ActualUploadFile = generalInformationModel.ActualUploadFile;
                tblGeneralInformationDb.Status           = 1;
                tblGeneralInformationDb.CreatedBy        = ClientSessionData.UserClientId;
                tblGeneralInformationDb.CreatedOn        = DateTime.UtcNow;
                tblGeneralInformationDb.CreatedFromIP    = HttpContext.Current.Request.UserHostAddress;
                tblGeneralInformationDb.ModifiedBy       = ClientSessionData.UserClientId;
                tblGeneralInformationDb.ModifiedOn       = DateTime.UtcNow;
                tblGeneralInformationDb.ModifiedFromIP   = HttpContext.Current.Request.UserHostAddress;
                tblGeneralInformationDb.StratasBoardId   = ClientSessionData.ClientStrataBoardId;


                if (generalInformationModel.GeneralInformationId > 0)
                {
                    tblGeneralInformationDb.GeneralInformationId = generalInformationModel.GeneralInformationId;
                    _context.tblGeneralInformations.Attach(tblGeneralInformationDb);
                    _context.Entry(tblGeneralInformationDb).Property(x => x.Title).IsModified            = true;
                    _context.Entry(tblGeneralInformationDb).Property(x => x.Description).IsModified      = true;
                    _context.Entry(tblGeneralInformationDb).Property(x => x.ActualUploadFile).IsModified = true;
                    _context.Entry(tblGeneralInformationDb).Property(x => x.UploadFile).IsModified       = true;
                    _context.Entry(tblGeneralInformationDb).Property(x => x.ModifiedBy).IsModified       = true;
                    _context.Entry(tblGeneralInformationDb).Property(x => x.ModifiedOn).IsModified       = true;
                    _context.Entry(tblGeneralInformationDb).Property(x => x.ModifiedFromIP).IsModified   = true;
                    result = _context.SaveChanges();
                }
                else
                {
                    _context.tblGeneralInformations.Add(tblGeneralInformationDb);
                    result = _context.SaveChanges();
                }
            }
            catch
            {
            }
            return(result);
        }
        public List <GeneralInformationModel> GetAllGeneralInformation(int BlockNumber, int BlockSize, string SearchKeyword)
        {
            if (ClientSessionData.UserClientId != 0)
            {
                int startIndex = (BlockNumber - 1) * BlockSize;
                List <GeneralInformationModel> generalInformationModelList = new List <GeneralInformationModel>();
                try
                {
                    var GeneralInformations = _context.tblGeneralInformations.Where(x => x.StratasBoardId == ClientSessionData.ClientStrataBoardId && x.Status == 1).OrderByDescending(x => x.CreatedOn).ToList();

                    if (!string.IsNullOrEmpty(SearchKeyword))
                    {
                        GeneralInformations = _context.tblGeneralInformations.Where(x => x.StratasBoardId == ClientSessionData.ClientStrataBoardId && x.Status == 1 && (x.Title.StartsWith(SearchKeyword) || x.Description.StartsWith(SearchKeyword))).OrderByDescending(x => x.CreatedOn).ToList();
                    }

                    foreach (var item in GeneralInformations)
                    {
                        GeneralInformationModel generalInformationModel = new GeneralInformationModel();
                        generalInformationModel.GeneralInformationId = item.GeneralInformationId;
                        generalInformationModel.Title            = item.Title;
                        generalInformationModel.Description      = item.Description;
                        generalInformationModel.UploadFile       = item.UploadFile;
                        generalInformationModel.ActualUploadFile = item.ActualUploadFile;
                        generalInformationModel.CreatedOn        = item.CreatedOn != null?item.CreatedOn.Value.ToString("dd MMM, yyyy") : "N/A";

                        generalInformationModelList.Add(generalInformationModel);
                    }
                }
                catch
                {
                }
                generalInformationModelList = generalInformationModelList.Skip(startIndex).Take(BlockSize).ToList();
                return(generalInformationModelList);
            }
            else
            {
                return(null);
            }
        }
 public void DownloadUploadedFile(int GeneralInformationId)
 {
     string FilePath = "resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/generalinformation";
     GeneralInformationModel model = noticeBoardHelper.GetGeneralInformationDetail(GeneralInformationId);
     //return AwsS3Bucket.DownloadObject(model.UploadFile, FilePath);
 }
        public ActionResult ViewGeneralInformation(int GeneralInformationId)
        {
            GeneralInformationModel model = noticeBoardHelper.GetGeneralInformationDetail(GeneralInformationId);

            return(PartialView("ViewGeneralInformation", model));
        }
        public ActionResult EditGeneralInformation(GeneralInformationModel model, HttpPostedFileBase FileUpload1)
        {
            int    result = 0;
            string strMsg = "";

            try
            {
                var imageTypes = new string[] {
                    "image/png",
                    "image/jpg",
                    "image/pjpeg",
                    "application/pdf",
                    "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                    "application/vnd.openxmlformats-officedocument.presentationml.presentation",
                };
                if (!imageTypes.Contains(FileUpload1.ContentType))
                {
                    strMsg = "User can add the file with extension (.jpg, .png, .pdf, .docx, .pptx, .xlsx)";
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        model.ActualUploadFile = System.IO.Path.GetFileName(FileUpload1.FileName);
                        model.UploadFile       = Guid.NewGuid() + System.IO.Path.GetExtension(FileUpload1.FileName);
                        result = noticeBoardHelper.AddUpdateGeneralInformation(model);

                        string path = "~/Content/Resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/generalinformation/";
                        if (!Directory.Exists(Server.MapPath(path)))
                        {
                            Directory.CreateDirectory(Server.MapPath(path));
                        }
                        string Mappedpath = Server.MapPath(path + model.UploadFile);


                        if (result == 1)
                        {
                            // save the file locally
                            FileUpload1.SaveAs(Mappedpath);
                            // save the file on s3
                            int fileMapped = AwsS3Bucket.CreateFile("resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/generalinformation/" + model.UploadFile, Mappedpath);
                            // delete the file locally

                            if (System.IO.File.Exists(Mappedpath))
                            {
                                System.IO.File.Delete(Mappedpath);
                            }

                            string OldProfilePath = Server.MapPath(path + model.OldUploadFile);
                            if (System.IO.File.Exists(OldProfilePath))
                            {
                                System.IO.File.Delete(OldProfilePath);
                            }
                            // delete the old file from s3
                            AwsS3Bucket.DeleteObject("resources/strataboard/" + ClientSessionData.ClientStrataBoardId + "/generalinformation/" + model.OldUploadFile);

                            strMsg = "General Information updated successfully.";
                        }
                        else
                        {
                            strMsg = "General Information updation failed.";
                        }
                    }
                }
            }
            catch
            {
            }
            return(Json(new { result = result, Msg = strMsg }));
        }
        public ActionResult AddGeneralInformation()
        {
            GeneralInformationModel model = new GeneralInformationModel();

            return(PartialView("AddGeneralInformation", model));
        }