예제 #1
0
        public Response <RfpAttachment> Add(RfpAttachment item, string user)
        {
            try
            {
                item.rfa_key = Guid.NewGuid();
                DynamicParameters _params = new DynamicParameters();
                _params.Add("@rfa_key", item.rfa_key, DbType.Guid);
                _params.Add("@rfa_rfp_key", item.rfa_rfp_key, DbType.Guid);
                _params.Add("@rfa_rfr_key", item.rfa_rfr_key, DbType.Guid);
                _params.Add("@rfa_cxr_key", item.rfa_cxr_key, DbType.Guid);
                _params.Add("@rfa_prd_key", item.rfa_prd_key, DbType.Guid);
                _params.Add("@rfa_org_key", item.rfa_org_key, DbType.Guid);
                _params.Add("@rfa_file_name", item.rfa_file_name, DbType.String);
                _params.Add("@rfa_file_path", item.rfa_file_path, DbType.String);
                _params.Add("@rfa_type", item.rfa_type, DbType.String);
                _params.Add("@rfa_mime", item.rfa_mime, DbType.String);
                _params.Add("@rfa_attachment", item.rfa_attachment, DbType.Binary);
                _params.Add("@rfa_add_user", user, DbType.String);
                _params.Add("@success", DbType.Boolean, direction: ParameterDirection.Output);

                var result = _dBConnection.Execute("USP_Rfp_Attachment_Add", _params, null, null, CommandType.StoredProcedure);

                return(new Response <RfpAttachment>(item)
                {
                    Success = _params.Get <Int32>("success") == 1 ? true : false
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public ActionResult Index()
        {
            try
            {
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file           = Request.Files[0];
                    string             baseFolderPath = Server.MapPath(ConfigHelper.GetSettingAsString("UploadsFolderPath"));
                    string             folderPath     = DateTime.Today.ToString("yyyyMM");
                    string             fileName       = Guid.NewGuid() + Path.GetFileNameWithoutExtension(file.FileName).RemoveSpecialChars() + Path.GetExtension(file.FileName);
                    string             fillFullName   = Path.Combine(baseFolderPath, folderPath, fileName);
                    Directory.CreateDirectory(Path.GetDirectoryName(fillFullName));

                    if (file.IsImage())
                    {
                        Image.FromStream(file.InputStream).SaveImage(Path.Combine(baseFolderPath, folderPath), fileName);
                    }
                    else
                    {
                        file.SaveAs(fillFullName);
                    }

                    RfpAttachment upload = new RfpAttachment
                    {
                        rfa_key       = Guid.NewGuid(),
                        rfa_rfp_key   = null,
                        rfa_rfr_key   = null,
                        rfa_cxr_key   = null,
                        rfa_prd_key   = null,
                        rfa_org_key   = null,
                        rfa_file_name = fileName,
                        rfa_file_path = folderPath,
                        rfa_mime      = file.ContentType,
                        rfa_add_date  = DateTime.Now,
                        rfa_add_user  = string.Empty,
                    };

                    var result = _rfpAttachmentFacade.Add(upload, "");

                    return(Json(new { rfa_key = upload.rfa_key, message = "success", Url = Path.Combine(Utility.GetSetting("UploadsURL"), folderPath, fileName) }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { message = "error" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { message = "error" }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #3
0
 public Response <RfpAttachment> Update(RfpAttachment item, string user)
 {
     return(_rfpAttachmentRepositoryDAC.Update(item, user));
 }