示例#1
0
        public string GetUsedSpaceInfo(string userId)
        {
            //var user = context.Users.FirstOrDefault(u => u.Id == userId);
            var user = this.FindById(userId);

            double totalSpace_inMegaBytes = ByteConvert.BytesToMegaBytes(ServerConstants.UserStorageSpace);
            double usedSpace_inMegaBytes  = Math.Round(ByteConvert.BytesToMegaBytes(user.FileSize_Total), 2);
            int    usedSpace_inPercents   = (int)Math.Round(usedSpace_inMegaBytes * 100.0 / totalSpace_inMegaBytes);

            // "Used 14% of storage space (14 MB / 100 MB)"
            string outputMessage = "Used " + usedSpace_inPercents + "% of storage space ("
                                   + usedSpace_inMegaBytes + " MB / " + totalSpace_inMegaBytes + " MB)";

            return(outputMessage);
        }
        public static MvcHtmlString FormatFileSize(this HtmlHelper htmlHelper, int bytes)
        {
            if (bytes < 500 * 1024)
            {
                var kiloByteValue = ByteConvert.BytesToKiloBytes(bytes);
                var roundedValue  = Math.Round(kiloByteValue);

                var formattedValue = roundedValue.ToString() + " KB";

                return(MvcHtmlString.Create(formattedValue.ToString()));
            }
            else
            {
                var megaByteValue = ByteConvert.BytesToMegaBytes(bytes);
                var roundedValue  = Math.Round(megaByteValue, 2);

                var formattedValue = roundedValue.ToString() + " MB";

                return(MvcHtmlString.Create(formattedValue.ToString()));
            }
        }