Ejemplo n.º 1
0
 /// <summary>
 /// Convert output bool
 /// </summary>
 /// <param name="data">Boolean?</param>
 /// <returns>String</returns>
 public static string ToString(bool?data)
 {
     // Check data
     if (DataCheckHelper.IsNull(data))
     {
         return(string.Empty);
     }
     // Return value
     return(data.Value ? bool.TrueString : bool.FalseString);
 }
Ejemplo n.º 2
0
        public static PagerResult <T> GetPagerList <T>(IList <T> list, PagerSupport criteria)
        {
            var result = new PagerResult <T>();
            var limit  = 20;
            var offset = 0;

            if (!DataCheckHelper.IsNull(criteria.Limit))
            {
                limit = decimal.ToInt32(criteria.Limit.Value);
                if (limit <= 0)
                {
                    limit = 10;
                }
            }
            if (!DataCheckHelper.IsNull(criteria.Offset))
            {
                offset = decimal.ToInt32(criteria.Offset.Value);
                if (offset <= 0 || offset > list.Count)
                {
                    offset = 0;
                }
            }

            result.AllRecordCount = list.Count;
            result.Limit          = limit;
            result.Offset         = offset;

            var start = list.Count > offset ? offset : 0;
            var end   = list.Count > offset + limit ? offset + limit : list.Count > offset ? list.Count : 0;

            result.AddAll(list.Skip(start).Take(end - start).ToList());

            if (!DataCheckHelper.IsNull(criteria.SortBy))
            {
                if (IsSortField <T>(criteria.SortBy))
                {
                    var ex = GetExpressionSort <T>(criteria.SortBy);
                    if (DataCheckHelper.IsNull(criteria.IsAsc))
                    {
                        criteria.IsAsc = true;
                    }
                    if (criteria.IsAsc.Value)
                    {
                        result.ResultList = result.AsQueryable().OrderBy(ex).ToList();
                    }
                    else
                    {
                        result.ResultList = result.AsQueryable().OrderByDescending(ex).ToList();
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Convert output date
        /// </summary>
        /// <param name="format">String</param>
        /// <param name="data">DateTime</param>
        /// <returns>String</returns>
        public static string ToString(string format, DateTime?data)
        {
            // Local variable declaration
            var provider = Thread.CurrentThread.CurrentCulture;

            // Check data
            if (DataCheckHelper.IsNull(data))
            {
                return(string.Empty);
            }
            // Return value
            return(string.Format(provider, format, data));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Convert input stream
        /// </summary>
        /// <param name="target">Stream</param>
        /// <returns>Stream</returns>
        public static Stream ConvertInputStream(Stream data)
        {
            // Local variable declaration
            var result = Stream.Null;

            // Check data
            if (!DataCheckHelper.IsNull(data))
            {
                result = data;
            }
            // Return value
            return(result);
        }
Ejemplo n.º 5
0
        public static T CopyPagerRequest <T>(PagerRequest request, PagerSupport criteria)
        {
            criteria.Limit  = DataHelper.ConvertInputNumber(request.Limit);
            criteria.Offset = DataHelper.ConvertInputNumber(request.Offset);
            criteria.SortBy = DataHelper.ConvertInputString(request.SortBy);

            if (!DataCheckHelper.IsNull(criteria.SortBy))
            {
                criteria.IsAsc = DataHelper.ConvertInputBoolean(request.IsAsc);
            }

            return(DataHelper.AutoCast <T>(criteria));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Convert output number
        /// </summary>
        /// <param name="format">String</param>
        /// <param name="data">Decimal</param>
        /// <returns>String</returns>
        public static string ToString(string format, decimal?data)
        {
            // Local variable declaration
            var result   = decimal.Zero;
            var provider = Thread.CurrentThread.CurrentCulture;

            // Check data
            if (!DataCheckHelper.IsNull(data))
            {
                result = data.Value;
            }
            // Return value
            return(string.Format(provider, format, result));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get day of week
        /// </summary>
        /// <param name="data">String</param>
        /// <param name="add">Int32</param>
        /// <returns>Day of week</returns>
        public static string GetDayOfWeek(DateTime data, int add)
        {
            // Local variable declaration
            IFormatProvider provider = Thread.CurrentThread.CurrentCulture;

            // Check data
            if (DataCheckHelper.IsNull(data))
            {
                return(string.Empty);
            }
            // Variable initialize
            data = data.AddDays(add);
            // Return value
            return(data.ToString("dddd", provider));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Convert output currency
        /// </summary>
        /// <param name="data">Decimal</param>
        /// <param name="localeId">String</param>
        /// <returns>String currency</returns>
        public static string ToCurrencyByLocale(decimal?data, string localeId)
        {
            // Local variable declaration
            var culture = new CultureInfo(localeId);
            var format  = Formats.ResourceManager.GetString("CURRENCY", culture);
            var value   = decimal.Zero;

            // Check data
            if (!DataCheckHelper.IsNull(data))
            {
                value = data.Value;
            }
            // Return value
            return(string.Format(culture, format, value));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Join string array with delimiter
        /// </summary>
        /// <param name="data">Array string</param>
        /// <param name="delimiter">delimiter</param>
        /// <returns>String</returns>
        public static string JoinStringArray(string[] data, string delimiter)
        {
            var result = new StringBuilder();

            foreach (var s in data)
            {
                if (!DataCheckHelper.IsNull(result.ToString()))
                {
                    result.Append(delimiter);
                }

                result.Append(s);
            }
            return(result.ToString());
        }
Ejemplo n.º 10
0
        public static bool AuthRole(string roleCd)
        {
            var userCom = new UserCom();
            var userCd  = PageHelper.UserCd;

            if (DataCheckHelper.IsNull(userCd))
            {
                return(false);
            }
            if (!userCom.IsExist(userCd, false))
            {
                return(false);
            }
            var roles = userCom.GetUserRoles(userCd, false);

            if (!roles.Contains(roleCd))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Convert string to string
 /// </summary>
 /// <param name="data">String</param>
 /// <returns>String</returns>
 public static string ToString(string data)
 {
     return((DataCheckHelper.IsNull(data)) ? string.Empty : data);
 }