Esempio n. 1
0
        public ResponseInfoModel Getinfo()
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                var output = _systemConfigurationService.FirstOrDefault();
                json.Result = output;
            }
            catch (Exception e)
            {
                DisposeUserFriendlyException(e, ref json, "api/sysconfig/getinfo", LocalizationConst.QueryFail);
            }
            return(json);
        }
Esempio n. 2
0
        public JsonResult GetSpatchTimeDefault()
        {
            var spatchTimeDefault       = 0;
            var configSpatchTimeDefault = _systemConfigurationService.FirstOrDefault(o => o.SystemConfigType == SystemConfigType.DispatchTimeDefault);

            if (configSpatchTimeDefault != null)
            {
                spatchTimeDefault = Convert.ToInt32(configSpatchTimeDefault.Value);
            }


            var a = DateTime.UtcNow;
            var b = DateTime.UtcNow.AddMinutes(spatchTimeDefault);
            var c = DateTime.UtcNow.AddMinutes(spatchTimeDefault).ToClientTimeDateTime();


            var clientsJson = Json(new
            {
                SpatchTimeDefault = DateTime.UtcNow.AddMinutes(spatchTimeDefault).ToClientTimeDateTime().ToString("hh:mm tt")
            }, JsonRequestBehavior.AllowGet);

            return(clientsJson);
        }
Esempio n. 3
0
        public ResponseInfoModel Upload()
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                string filename;
                string format;
                string newName;
                int    contentlength;
                int    fileType;
                string attachUrl;

                var    systemConfig = _systemConfigurationService.FirstOrDefault();
                string uploadPath   = systemConfig.Uploadpath;

                //如果目录不存在,则创建目录
                if (!Directory.Exists(HttpContext.Current.Server.MapPath(uploadPath)))
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath(uploadPath));
                }

                HttpPostedFile f = HttpContext.Current.Request.Files[0];

                //获取文件MD5
                MD5    md5    = new MD5CryptoServiceProvider();
                byte[] retVal = md5.ComputeHash(f.InputStream);
                //f.InputStream.Close();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < retVal.Length; i++)
                {
                    sb.Append(retVal[i].ToString("x2"));
                }
                string fileMD5 = sb.ToString();

                //查询数据库中有相同文件则不重新上传
                var SameHashFile = _articleAttachService.FirstOrDefault(a => a.HashValue == fileMD5);
                //判断文件在服务器上是否还存在
                if (SameHashFile != null && IsExists(SameHashFile.AttachUrl))
                {
                    filename      = f.FileName;
                    format        = SameHashFile.AttachFormat;
                    contentlength = SameHashFile.AttachBytes;
                    newName       = SameHashFile.AttachNewName;
                    fileType      = SameHashFile.AttachType;
                    attachUrl     = SameHashFile.AttachUrl;
                }
                else
                {
                    filename      = f.FileName;
                    format        = Path.GetExtension(filename).ToLower();
                    newName       = DateTime.Now.ToString("yyyyMMddHHmmssfffffff") + format;
                    contentlength = f.ContentLength;
                    string[] imgTypes = systemConfig.ImgFormat.ToLower().Split(',');
                    fileType  = imgTypes.Contains(format) ? 1 : 0;
                    attachUrl = uploadPath + newName;
                    f.SaveAs(HttpContext.Current.Server.MapPath(uploadPath) + newName);
                }

                var output = new UploadAttachOutput()
                {
                    AttachFormat  = format,
                    AttachBytes   = contentlength,
                    AttachName    = filename,
                    AttachNewName = newName,
                    AttachType    = fileType,
                    AttachUrl     = attachUrl,
                    HashValue     = fileMD5
                };
                json.Result = output;
            }
            catch (Exception e)
            {
                DisposeUserFriendlyException(e, ref json, "api/attach/upload", LocalizationConst.UploadFail);
            }
            return(json);
        }