public ActionResult UploadifyImage(UploadifyModel @params) { try { Response.ContentType = "text/plain"; Response.Charset = "UTF-8"; HttpFileCollectionBase filecollection = Request.Files; HttpPostedFileBase postedfile = filecollection.Get("filedata"); if (postedfile == null) { return Content(new { Url = "", ThumbnailUrl = "" }.ToJson()); } int compressionRatio = 90; string dirName = _configService.GetByKey<string>("UploadImageDir", "Images"); string savePath = saveRootPath + "/" + dirName + "/" + DateTime.Now.Year + "/" + DateTime.Now.Month; if (!Directory.Exists(root + "/" + savePath)) Directory.CreateDirectory(root + "/" + savePath); string saveName = Guid.NewGuid() + "_0"; string ext = postedfile.FileName.GetExtension(); string fullFileName = saveName + ext; string fullFileSavePath = savePath + "/" + fullFileName; postedfile.SaveAs(root + "/" + fullFileSavePath); if (@params.CreateRule.HasValue()) { if (!"0,0".Equals(@params.CreateRule)) { var createRuleArray = @params.CreateRule.Split('|'); var index = 0; foreach (var item in createRuleArray) { index++; var ruleDetailArray = item.Split(','); if (ruleDetailArray.Length > 1) { var maxLength = ruleDetailArray[0].ToInt(150); var createType = "Cut"; switch (ruleDetailArray[1]) { case "0": createType = "DB"; break; case "1": createType = "W"; break; case "2": createType = "H"; break; default: break; } var fullThumbnailSavePath = savePath + "/" + saveName.Replace("_0", "_" + index) + ext; ImageHelper.MakeThumbnail(root + "/" + fullFileSavePath, root + "/" + fullThumbnailSavePath, maxLength, maxLength, createType, compressionRatio); } } var isSaveOriginalImage = _configService.GetByKey<bool>("UploadIsSaveOriginalImage", true); if (!isSaveOriginalImage) { System.IO.File.Delete(root + "/" + fullFileSavePath); } } } var result = new { Url = @params.UploadPath + "/" + fullFileSavePath }; return Content(result.ToJson()); } catch (Exception ex) { _logger.Error(ex); } return Content("{Url:\"\"}"); }
public bool CheckUserNameIsExist(string userName, int? userId = null) { var list=new []{ "admin" ,"passport","boss" }; foreach (var item in list) { if (userName.ToLower().IndexOf(item) >= 0) { throw new BusinessException("用户名不能包含:" + item); } } if (userId.HasValue) return _rep.Query<EUser, int>() .Where(p => p.UserName == userName && p.Id != userId.Value) .Select(p => p.Id.DMCount()) .Excute() != 0; return _rep.Query<EUser, int>() .Where(p => p.UserName == userName) .Select(p => p.Id.DMCount()) .Excute() != 0; }
public ActionResult UploadifyFile(UploadifyModel @params) { try { Response.ContentType = "text/plain"; Response.Charset = "UTF-8"; HttpFileCollectionBase filecollection = Request.Files; HttpPostedFileBase postedfile = filecollection.Get("filedata"); if (postedfile == null) { return Content(new { Url = "", ThumbnailUrl = "" }.ToJson()); } string dirName = _configService.GetByKey<string>("UploadFileDir", "Files"); string savePath = saveRootPath + "/" + dirName + "/" + DateTime.Now.Year + "/" + DateTime.Now.Month; if (!Directory.Exists(root + "/" + savePath)) Directory.CreateDirectory(root + "/" + savePath); string saveName = Guid.NewGuid().ToString(); string ext = postedfile.FileName.GetExtension(); string fullFileName = saveName + ext; string fullFileSavePath = savePath + "/" + fullFileName; postedfile.SaveAs(root + "/" + fullFileSavePath); var result = new { Url = @params.UploadPath + "/" + fullFileSavePath }; return Content(result.ToJson()); } catch (Exception ex) { _logger.Error(ex); } return Content("{Url:\"\"}"); }