public LibraryImageInfo Create() { var auth = new AuthenticatedRequest(); if (!auth.IsAdminLoggin || !auth.AdminPermissionsImpl.HasSitePermissions(auth.SiteId, ConfigManager.SitePermissions.Library)) { return(Request.Unauthorized <LibraryImageInfo>()); } var library = new LibraryImageInfo { GroupId = auth.GetQueryInt("groupId") }; var fileName = auth.HttpRequest["fileName"]; var fileCount = auth.HttpRequest.Files.Count; if (fileCount == 0) { return(Request.BadRequest <LibraryImageInfo>("请选择有效的文件上传")); } var file = auth.HttpRequest.Files[0]; if (string.IsNullOrEmpty(fileName)) { fileName = Path.GetFileName(file.FileName); } if (!PathUtils.IsExtension(PathUtils.GetExtension(fileName), ".jpg", ".jpeg", ".bmp", ".gif", ".png", ".svg", ".webp")) { return(Request.BadRequest <LibraryImageInfo>("文件只能是图片格式,请选择有效的文件上传!")); } var libraryFileName = PathUtils.GetLibraryFileName(fileName); var virtualPath = PathUtils.GetLibraryVirtualPath(EUploadType.Image, libraryFileName); var filePath = PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, virtualPath); DirectoryUtils.CreateDirectoryIfNotExists(filePath); file.SaveAs(filePath); library.Title = fileName; library.Url = virtualPath; library.Id = DataProvider.LibraryImageDao.Insert(library); return(library); }
public void Update(LibraryImageInfo group) { var sqlString = $@"UPDATE {TableName} SET {nameof(LibraryImageInfo.Title)} = @{nameof(LibraryImageInfo.Title)}, {nameof(LibraryImageInfo.GroupId)} = @{nameof(LibraryImageInfo.GroupId)}, {nameof(LibraryImageInfo.Url)} = @{nameof(LibraryImageInfo.Url)} WHERE {nameof(LibraryImageInfo.Id)} = @{nameof(LibraryImageInfo.Id)}"; IDataParameter[] parameters = { GetParameter(nameof(LibraryImageInfo.Title), DataType.VarChar, 500, group.Title), GetParameter(nameof(LibraryImageInfo.GroupId), DataType.Integer, group.GroupId), GetParameter(nameof(LibraryImageInfo.Url), DataType.VarChar, 500, group.Url), GetParameter(nameof(LibraryImageInfo.Id), DataType.Integer, group.Id) }; ExecuteNonQuery(sqlString, parameters); }
public LibraryImageInfo Update([FromUri] int id, [FromBody] LibraryImageInfo library) { var auth = new AuthenticatedRequest(); if (!auth.IsAdminLoggin || !auth.AdminPermissionsImpl.HasSitePermissions(auth.SiteId, ConfigManager.SitePermissions.Library)) { return(Request.Unauthorized <LibraryImageInfo>()); } var lib = DataProvider.LibraryImageDao.Get(id); lib.Title = library.Title; lib.GroupId = library.GroupId; DataProvider.LibraryImageDao.Update(lib); return(library); }
public int Insert(LibraryImageInfo group) { var sqlString = $@"INSERT INTO {TableName} ({nameof(LibraryImageInfo.Title)}, {nameof(LibraryImageInfo.GroupId)}, {nameof(LibraryImageInfo.Url)}) VALUES (@{nameof(LibraryImageInfo.Title)}, @{nameof(LibraryImageInfo.GroupId)}, @{nameof(LibraryImageInfo.Url)})"; IDataParameter[] parameters = { GetParameter(nameof(LibraryImageInfo.Title), DataType.VarChar, 500, group.Title), GetParameter(nameof(LibraryImageInfo.GroupId), DataType.Integer, group.GroupId), GetParameter(nameof(LibraryImageInfo.Url), DataType.VarChar, 500, group.Url), }; return(ExecuteNonQueryAndReturnId(TableName, nameof(LibraryImageInfo.Id), sqlString, parameters)); }
private static LibraryImageInfo GetLibraryImageInfo(IDataRecord rdr) { if (rdr == null) { return(null); } var libraryGroupInfo = new LibraryImageInfo(); var i = 0; libraryGroupInfo.Id = rdr.IsDBNull(i) ? 0 : rdr.GetInt32(i); i++; libraryGroupInfo.Title = rdr.IsDBNull(i) ? string.Empty : rdr.GetString(i); i++; libraryGroupInfo.GroupId = rdr.IsDBNull(i) ? 0 : rdr.GetInt32(i); i++; libraryGroupInfo.Url = rdr.IsDBNull(i) ? string.Empty : rdr.GetString(i); return(libraryGroupInfo); }
public LibraryImageInfo Get(int libraryId) { LibraryImageInfo accessTokenInfo = null; var sqlString = $@"SELECT {nameof(LibraryImageInfo.Id)}, {nameof(LibraryImageInfo.Title)}, {nameof(LibraryImageInfo.GroupId)}, {nameof(LibraryImageInfo.Url)} FROM {TableName} WHERE {nameof(LibraryImageInfo.Id)} = {libraryId}"; using (var rdr = ExecuteReader(sqlString)) { if (rdr.Read()) { accessTokenInfo = GetLibraryImageInfo(rdr); } rdr.Close(); } return(accessTokenInfo); }