示例#1
0
        public long AddNewPMB(PMBModel _model)
        {
            try
            {
                if (_model.Attachment != null)
                {
                    Guid   guid = Guid.NewGuid();
                    string ext  = System.IO.Path.GetExtension(_model.Attachment.FileName);
                    _model.AttachedActualFileName = _model.Attachment.FileName;
                    _model.AttachedFileName       = guid.ToString() + ext;
                }
                tblPMB _pmbModel = new tblPMB();
                _pmbModel.QuotationRequestId     = _model.QuotatoinId;
                _pmbModel.AttachedFileActualName = _model.AttachedActualFileName;
                _pmbModel.AttachedFileName       = _model.AttachedFileName;
                _pmbModel.CreatedBy         = _model.CreatedBy;
                _pmbModel.CreatedFromIP     = HttpContext.Current.Request.UserHostAddress;
                _pmbModel.CreatedOn         = DateTime.UtcNow;
                _pmbModel.CreatedByUserType = _model.CreatedByUserType;
                _pmbModel.Message           = _model.Message;
                using (StratasFairDBEntities context = new StratasFairDBEntities())
                {
                    context.tblPMBs.Add(_pmbModel);
                    _model.PMBId = context.SaveChanges();
                }
                if (_model.PMBId > 0)
                {
                    if (_model.Attachment != null)
                    {
                        string path        = string.Empty;
                        string initialPath = "resources/vendor-owner-pmb/" + _model.QuotatoinId;

                        // 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);
            }
        }
示例#2
0
        public ActionResult PMB(PMBModel _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));
                }
            }
            _model.CreatedByUserType = "V";
            _model.CreatedBy         = VendorSessionData.Instance.VendorId;

            if (PMBHelper.Instance.AddNewPMB(_model) > 0)
            {
                return(RedirectToAction("PMB"));
            }
            return(View(_model));
        }
示例#3
0
        public ActionResult OwnerPMB(PMBModel _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) + " file types 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));
                }
            }
            _model.CreatedByUserType = "O";
            _model.CreatedBy         = ClientSessionData.UserClientId;
            if (PMBHelper.Instance.AddNewPMB(_model) > 0)
            {
                return(Redirect(Url.Content("~/" + ClientSessionData.ClientPortalLink + "/pmb/" + _model.QuotatoinId)));
            }
            return(View(_model));
        }