Example #1
0
        public ActionResult Index(AdminPMBModel _model)
        {
            bool hasError = false;

            if (_model.Attachment != null)
            {
                List <string> fileTypes = new List <string> {
                    ".jpg", ".png", ".jpeg", ".pdf", ".ppt", ".xls", ".xlsx", ".doc", ".docx", ".txt"
                };
                if (!fileTypes.Contains(Path.GetExtension(_model.Attachment.FileName)))
                {
                    ModelState.AddModelError("Message", "Invalid File only " + String.Join(",", fileTypes) + " are allowed");
                    hasError = true;
                }
                if (_model.Attachment.ContentLength > (5 * 1024 * 1024))
                {
                    ModelState.AddModelError("Message", "Max file size 5 MB");
                    hasError = true;
                }
                if (string.IsNullOrEmpty(_model.Message))
                {
                    ModelState.AddModelError("Message", "Message is required");
                    hasError = true;
                }
                if (hasError)
                {
                    return(View(_model));
                }
            }
            if (PMBHelper.Instance.AddNewAdminPMB(_model) > 0)
            {
                return(Redirect(Url.Content("~/" + ClientSessionData.ClientPortalLink + "/adminpmb?id=" + _model.CreatedFor)));
            }
            return(View(_model));
        }
Example #2
0
        // GET: PMB
        public ActionResult Index(long?id)
        {
            try
            {
                if (!PMBHelper.Instance.IsOwnerInStrataBoard(id, ClientSessionData.ClientStrataBoardId))
                {
                    TempData["Message"] = AppLogic.setFrontendMessage(-1, "Error: Please try again!");
                    return(Redirect(Url.Content("~/" + ClientSessionData.ClientPortalLink + "/dashboard")));
                }
                AdminPMBModel _model = new AdminPMBModel();
                if (ClientSessionData.ClientRoleName == "Admin" || ClientSessionData.ClientRoleName == "SubAdmin")
                {
                    _model.CreatedFor = id;
                }
                else
                {
                    _model.CreatedFor = ClientSessionData.UserClientId;
                }

                return(View(_model));
            }
            catch
            {
                TempData["Message"] = AppLogic.setFrontendMessage(-1, "Error: Please try again!");
                return(Redirect(Url.Content("~/dashboard")));
            }
        }
Example #3
0
        public long AddNewAdminPMB(AdminPMBModel _model)
        {
            try
            {
                if (_model.Attachment != null)
                {
                    Guid   guid = Guid.NewGuid();
                    string ext  = System.IO.Path.GetExtension(_model.Attachment.FileName);
                    _model.AttachedFileActualName = _model.Attachment.FileName;
                    _model.AttachedFileName       = guid.ToString() + ext;
                }
                tblAdminPMB _pmbModel = new tblAdminPMB();
                _pmbModel.AttachedFileActualName = _model.AttachedFileActualName;
                _pmbModel.AttachedFileName       = _model.AttachedFileName;
                _pmbModel.Message           = _model.Message;
                _pmbModel.CreatedBy         = ClientSessionData.UserClientId;
                _pmbModel.CreatedFromIP     = HttpContext.Current.Request.UserHostAddress;
                _pmbModel.CreatedOn         = DateTime.UtcNow;
                _pmbModel.CreatedFor        = _model.CreatedFor;
                _pmbModel.CreatedByUserType = ClientSessionData.ClientRoleName;
                _pmbModel.StrataBoardId     = ClientSessionData.ClientStrataBoardId;
                using (StratasFairDBEntities context = new StratasFairDBEntities())
                {
                    context.tblAdminPMBs.Add(_pmbModel);
                    _model.PMBId = context.SaveChanges();
                }
                if (_model.PMBId > 0)
                {
                    if (_model.Attachment != null)
                    {
                        string path        = string.Empty;
                        string initialPath = "resources/admin-owner-pmb/" + ClientSessionData.ClientStrataBoardId;

                        // Add/Delete the new trade and business file and image details
                        if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/pmbFiles/")))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/pmbFiles/"));
                        }
                        // save the file locally
                        path = HttpContext.Current.Server.MapPath(Path.Combine("~/Content/" + initialPath + "/pmbFiles/" + _model.AttachedFileName));
                        _model.Attachment.SaveAs(path);

                        // save the file on s3
                        AwsS3Bucket.CreateFile(initialPath + "/pmbFiles/" + _model.AttachedFileName, path);

                        // delete the file locally
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }
                }
                return(_model.PMBId);
            }
            catch (Exception)
            {
                return(-1);
            }
        }
Example #4
0
 public FileResult Download(AdminPMBModel model)
 {
     using (var client = new WebClient())
     {
         try
         {
             var content = client.DownloadData(AwsS3Bucket.AccessPath() + "/resources/admin-owner-pmb/" + model.StratasBoardId + "/pmbFiles/" + model.AttachedFileName);
             using (var stream = new MemoryStream(content))
             {
                 byte[] buff = stream.ToArray();
                 return(File(buff, MimeMapping.GetMimeMapping(model.AttachedFileName), model.AttachedFileActualName));
             }
         }
         catch (Exception ex)
         {
             TempData["Message"] = AppLogic.setMessage(-1, "Error! " + ex.Message);
         }
     }
     return(null);
 }