Пример #1
0
        public string FileUpload()
        {
            //string filename = "";
            //string ext = "";

            /*     byte[] data = Convert.FromBase64String(fileparam);
             *  string decodedString = Encoding.UTF8.GetString(data);
             *  Char delimiter = '/';
             *  String[] substrings = decodedString.Split(delimiter);
             *  if (substrings.Length >= 1)
             *      filename = substrings[0];
             *  if (substrings.Length >= 2)
             *      ext = substrings[1]; */
            string returnStr = "Fail to Upload";

            try
            {
                var files = Request.Form.Files;
                if (files.Count > 0)
                {
                    var    appsettingbuilder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
                    var    Configuration     = appsettingbuilder.Build();
                    string folderPath        = "";
                    string fullPath          = "";

                    /////////stockphoto/////////

                    folderPath = Configuration.GetSection("appSettings:uploadStockPath").Value;
                    fullPath   = folderPath + "pp" + "." + "png";

                    // Save the file
                    var file = files[0];
                    if (file.Length > 0)
                    {
                        using (var fileStream = new FileStream(fullPath, FileMode.OpenOrCreate))
                        {
                            file.CopyTo(fileStream);
                        }
                    }
                    Response.ContentType = "application/json";
                    returnStr            = "Succesfully Upload";
                }
            }
            catch (Exception ex)
            {
                returnStr = "Fail to Upload";
                Globalfunction.WriteSystemLog(ex.Message);
            }
            return(returnStr);
        }
Пример #2
0
 public void setDefaultDataFromToken()
 {
     try
     {
         string access_token = "";
         var    hdtoken      = Request.Headers["Authorization"];
         if (hdtoken.Count > 0)
         {
             access_token = hdtoken[0];
             access_token = access_token.Replace("Bearer ", "");
             var handler = new JwtSecurityTokenHandler();
             var tokenS  = handler.ReadToken(access_token) as JwtSecurityToken;
             _tokenData = Globalfunction.GetTokenData(tokenS);
         }
     }
     catch (Exception ex)
     {
         Globalfunction.WriteSystemLog(ex.Message);
     }
 }
Пример #3
0
        public dynamic ExecuteReader(string qry)
        {
            var retObject = new List <dynamic>();

            try
            {
                using (MySqlConnection conn = GetConnection())
                {
                    conn.Open();
                    MySqlCommand cmd = new MySqlCommand(qry, conn);
                    using (var dataReader = cmd.ExecuteReader())
                    {
                        while (dataReader.Read())
                        {
                            // var dataRow = new ExpandoObject() as IDictionary<string, object>;
                            var dataRow = new DynamicObject();
                            for (var iFiled = 0; iFiled < dataReader.FieldCount; iFiled++)
                            {
                                // one can modify the next line to
                                //   if (dataReader.IsDBNull(iFiled))
                                //       dataRow.Add(dataReader.GetName(iFiled), dataReader[iFiled]);
                                // if one want don't fill the property for NULL
                                dataRow.AddProperty(
                                    dataReader.GetName(iFiled),
                                    dataReader.IsDBNull(iFiled) ? null : dataReader[iFiled] // use null instead of {}
                                    );
                            }

                            retObject.Add(dataRow);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Globalfunction.WriteSystemLog(ex.Message);
            }
            return(retObject);
        }
        // [Authorize]
        public dynamic FileUpload(String functionname, string fileparam)
        {
            string filename = "";
            string ext      = "";

            byte[] data          = Convert.FromBase64String(fileparam);
            string decodedString = Encoding.UTF8.GetString(data);
            Char   delimiter     = '/';

            String[] substrings  = decodedString.Split(delimiter);
            dynamic  objresponse = null;

            // if (substrings.Length >= 2)
            // {
            //     path = substrings[0];
            //     ext = substrings[1];
            // }
            if (substrings.Length >= 1)
            {
                filename = substrings[0];
            }
            if (substrings.Length >= 2)
            {
                ext = substrings[1];
            }

            string returnStr   = "Fail to Upload";
            string retfilename = "";

            try
            {
                var    files             = Request.Form.Files;
                var    appsettingbuilder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
                var    Configuration     = appsettingbuilder.Build();
                string baseDirecotry     = Configuration.GetSection("appSettings:downloadPath").Value;
                string folderPath        = "";
                //string customerName = "";
                //string CompanyName = "";
                folderPath = Configuration.GetSection("appSettings:uploadMemberProfile").Value;
                // folderPath = baseDirecotry + folderPath + "/";
                folderPath = baseDirecotry;
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }
                // folderPath=Path.Combine(webRootPath,folderPath);

                string existingFile = Directory.EnumerateFiles(folderPath, filename + ".*").FirstOrDefault();
                string extension    = "";
                if (!string.IsNullOrEmpty(existingFile))
                {
                    extension = Path.GetExtension(existingFile);
                }
                string oldPath = folderPath + filename + extension;
                // delete old photo
                if (System.IO.File.Exists(oldPath))     // Read data when file exists.
                {
                    System.IO.File.Delete(oldPath);
                }
                folderPath  = folderPath + filename + "." + ext;
                retfilename = filename + "." + ext;
                //Member newMemberobj = _repositoryWrapper.Member.FindByID(Convert.ToInt32(filename));

                // newMemberobj.loginname = newMemberobj.loginname;
                // newMemberobj.memberphone = newMemberobj.memberphone;
                // newMemberobj.memberdob = newMemberobj.memberdob;
                // newMemberobj.memberaddress = newMemberobj.memberaddress;
                // newMemberobj.password = newMemberobj.password;
                // newMemberobj.email = newMemberobj.email;

                // newMemberobj.membercardnumber = newMemberobj.membercardnumber;
                // newMemberobj.membername = newMemberobj.membername;;
                // newMemberobj.pointbalance = newMemberobj.pointbalance;
                // newMemberobj.totalpointbalance = newMemberobj.totalpointbalance;
                // newMemberobj.cardtypekwid = newMemberobj.cardtypekwid;
                // newMemberobj.embossstatus = newMemberobj.embossstatus;
                // newMemberobj.branchcode = newMemberobj.branchcode;
                // newMemberobj.expireddate = newMemberobj.expireddate;
                // newMemberobj.issuedate = newMemberobj.issuedate;
                // newMemberobj.memberdob = newMemberobj.memberdob;
                //newMemberobj.photo = decodedString;
                // newMemberobj.openingpoint = newMemberobj.openingpoint;
                // newMemberobj.isactive = newMemberobj.isactive;
                // newMemberobj.partnerid = newMemberobj.partnerid;
                // newMemberobj.createdate = newMemberobj.createdate;
                // newMemberobj.createuser = newMemberobj.createuser;; //! need to ask ?
                // newMemberobj.nrc = newMemberobj.nrc;
                // newMemberobj.nrctype = newMemberobj.nrctype;
                // newMemberobj.customer_type = newMemberobj.customer_type;
                // newMemberobj.openingpointamount = newMemberobj.openingpointamount;
                // newMemberobj.totalpointamount = newMemberobj.totalpointamount;
                // newMemberobj.version = newMemberobj.version;
                // newMemberobj.amount = newMemberobj.amount;
                // newMemberobj.liter = newMemberobj.liter;

                //_repositoryWrapper.Member.Update(newMemberobj);

                // Save the file
                var file = files[0];
                if (file.Length > 0)
                {
                    using (var fileStream = new FileStream(folderPath, FileMode.OpenOrCreate))
                    {
                        file.CopyTo(fileStream);
                    }
                }
                Response.ContentType = "application/json";
                returnStr            = "Succesfully Upload  " + retfilename;
                objresponse          = new { status = 1, messages = returnStr };
            }
            catch (Exception ex)
            {
                Globalfunction.WriteSystemLog(ex.Message);
                // _repositoryWrapper.EventLog.Error("fileUpload(Exception) : " , ex.Message, "", "");
                Response.StatusCode = 500;
                dynamic uu = null;
                objresponse = new { status = 0, messages = uu };
                return(objresponse);
                // return null;
            }

            return(objresponse);
        }