示例#1
0
文件: DateHelpers.cs 项目: IYoni/cats
        public static decimal ToPreferedWeightUnit(this decimal amount, string unit = "MT")
        {
            string currentUnit;

            // Get current unit setting for the user.
            // NOTE: Since we might call this method from public views where we might not have a signed-in
            //       user, we must check for possible errors.
            try
            {
                var user = UserAccountHelper.GetCurrentUser();
                currentUnit = user.PreferedWeightMeasurment;
            }
            catch (Exception)
            {
                currentUnit = unit;
            }

            // If the current unit is 'Metric Tone' then return the  value (the passed value)
            if (currentUnit.ToUpper().Trim() == "MT")
            {
                return(amount);
            }

            // For the other unit (quintal)  multiply by 10

            return(amount * 10);
        }
示例#2
0
        public static int GetUnreadNotifications(this HtmlHelper helper)
        {
            try
            {
                var notificationService = (INotificationService)DependencyResolver.Current.GetService(typeof(INotificationService));

                var user = HttpContext.Current.User.Identity.Name;
                List <Cats.Models.Notification> totallUnread = null;
                var currentUser = UserAccountHelper.GetUser(user);
                var app         = GetApplication(user);

                if (app == Models.Constant.Application.HUB)
                {
                    totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && n.Id == currentUser.DefaultHub && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
                }
                else if (app == Models.Constant.Application.REGIONAL)
                {
                    totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && n.Id == currentUser.RegionID && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
                }
                else
                {
                    totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
                }

                return(totallUnread.Count());
            }
            catch (Exception)
            {
                return(0);
            }
        }
示例#3
0
        //public static int GetUnreadNotifications()
        //{
        //    try
        //    {

        //        var user = HttpContext.Current.User.Identity.Name;
        //        var app = GetApplication(user);

        //        var notificationService = (INotificationService)DependencyResolver.Current.GetService(typeof(INotificationService));
        //        var totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
        //        return totallUnread.Count();
        //    }
        //    catch (Exception)
        //    {
        //        return 0;
        //    }
        //}

        public static HtmlString GetActiveNotifications(this HtmlHelper helper)
        {
            try
            {
                var user = HttpContext.Current.User.Identity.Name;
                var notificationService = (INotificationService)DependencyResolver.Current.GetService(typeof(INotificationService));

                List <Cats.Models.Notification> totallUnread = null;
                var currentUser = UserAccountHelper.GetUser(user);
                var app         = GetApplication(user);

                if (app == Models.Constant.Application.HUB)
                {
                    totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && n.Id == currentUser.DefaultHub && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
                }
                else if (app == Models.Constant.Application.REGIONAL)
                {
                    totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && n.Id == currentUser.RegionID && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
                }
                else
                {
                    totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
                }



                var str = "<ul>";


                int max = 0;

                if (totallUnread.Count < 1)
                {
                    return(MvcHtmlString.Create(""));
                }
                max = totallUnread.Count > 5 ? 5 : totallUnread.Count;

                for (int i = 0; i < max; i++)
                {
                    str = str + "<li>";
                    str = str + "<a href=" + totallUnread[i].Url + ">";
                    str = str + totallUnread[i].Text;
                    str = str + "</li>";
                    str = str + "</a>";
                }

                str = str + "</ul>";
                if (totallUnread.Count > 5)
                {
                    str = str + "<a href=/Home/GetUnreadNotificationDetail>" + "More...</a>";
                }

                return(MvcHtmlString.Create(str));
            }
            catch (Exception)
            {
                return(MvcHtmlString.Create(""));
            }
        }
示例#4
0
        public static string isValidOperation(LogisticsConstants.Operation operation)
        {
            var    constants = new LogisticsConstants();
            string acces     = "";
            var    ewCache   = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Logistics);

            if (ewCache.CheckAccess(constants.ItemName(operation), DateTime.Now) == AuthorizationType.Allow)
            {
                acces = operation.ToString();
            }
            return(acces);
        }
示例#5
0
        private static string GetApplication(string user)
        {
            var currentUser = UserAccountHelper.GetUser(user);
            var userID      = currentUser.UserProfileID;

            if (currentUser.IsAdmin)
            {
                return(Cats.Models.Constant.Application.EARLY_WARNING);
            }
            if (currentUser.DefaultHub != null)
            {
                return(Cats.Models.Constant.Application.HUB);
            }
            if (currentUser.RegionalUser)
            {
                return(Cats.Models.Constant.Application.REGIONAL);
            }
            switch (currentUser.CaseTeam)
            {
            case 1:    //EarlyWarning
                return(Cats.Models.Constant.Application.EARLY_WARNING);

                break;

            case 2:    //PSNP
                return(Cats.Models.Constant.Application.PSNP);

                break;

            case 3:    //Logistics
                return(Cats.Models.Constant.Application.LOGISTICS);

                break;

            case 4:    //Procurement
                return(Cats.Models.Constant.Application.PROCUREMENT);

                break;

            case 5:    //Finance
                return(Cats.Models.Constant.Application.FINANCE);

                break;

            default:
                return("");
            }
        }
示例#6
0
        public static MvcHtmlString EarlyWarningOperationJsLink(this HtmlHelper helper, EarlyWarningConstants.Operation operation, string text = "", string clickFunction = "", string ccsClass = "btn-Approve-Gift", string dataButtontype = "", string id = "")
        {
            //return MvcHtmlString.Create(@"<a data-buttontype=" + dataButtontype + "  class=" + ccsClass + " href=" + url + ">" + text + "</a>");

            var constants = new EarlyWarningConstants();
            var ewCache   = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.EarlyWarning);

            // If cache is null then force the user to sign-in again
            if (null == ewCache)
            {
                Signout();
                return(MvcHtmlString.Create(string.Empty));
            }

            var html = string.Empty;

            if (ewCache.CheckAccess(constants.ItemName(operation), DateTime.Now) == AuthorizationType.Allow)
            {
                //html = @"<a data-buttontype=" + dataButtontype + " class=" + ccsClass + " href=" + url + ">" + text + "</a>";
                html = @"<a href='#'";
                if (ccsClass != "")
                {
                    html += " class='btn-success'";
                }
                if (id != "")
                {
                    html += " id=" + id;
                }
                if (dataButtontype != "")
                {
                    html += " data-buttontype=" + dataButtontype;
                }
                html += ">";
                if (clickFunction != "" && text != "")
                {
                    html += "<button type = 'button' class='btn btn-xs btn-success' ><span class='fa fa-check'></span>" + text + "</button></a>";
                }
                else
                {
                    html += " ><span class='fa fa-check'></span></a>";
                }
            }
            return(MvcHtmlString.Create(html));
        }
示例#7
0
        public static MvcHtmlString FinanceOperationMenuItem(this HtmlHelper helper, string text, string url, FinanceConstants.Operation operation, string ccsClass = "", string dataButtontype = "")
        {
            var constants = new FinanceConstants();
            var ewCache   = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Finance);

            var html = string.Empty;

            // If cache is null then force the user to sign-in again
            if (null == ewCache)
            {
                Signout();
                return(MvcHtmlString.Create(string.Empty));
            }
            else if (ewCache.CheckAccess(constants.ItemName(operation), DateTime.Now) == AuthorizationType.Allow)
            {
                html = @"<a data-buttontype=" + dataButtontype + "  class=" + ccsClass + " href=" + url + ">" + text + "</a>";
            }
            return(MvcHtmlString.Create(html));
        }
示例#8
0
        public static MvcHtmlString AdminOperationMenuItem(this HtmlHelper helper, string text, string url, string ccsClass = "", string dataButtontype = "")
        {
            var ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Finance);

            var html = string.Empty;

            // If cache is null then force the user to sign-in again
            if (null == ewCache)
            {
                Signout();
                return(MvcHtmlString.Create(string.Empty));
            }
            else
            {
                html = @"<a data-buttontype=" + dataButtontype + "  class=" + ccsClass + " href=" + url + ">" + text + "</a>";
            }

            return(MvcHtmlString.Create(html));
        }
示例#9
0
文件: DateHelpers.cs 项目: IYoni/cats
        public static float GetPreferedRation1(this decimal amount)
        {
            string currentUnit;

            try
            {
                var user = UserAccountHelper.GetCurrentUser();
                currentUnit = user.PreferedWeightMeasurment;
            }
            catch (Exception)
            {
                return((float)amount);
            }


            if (currentUnit.ToUpper().Trim() == "MT")
            {
                return((float)(amount / 1000));
            }
            return((float)(amount / 100));
        }
示例#10
0
        public static MvcHtmlString EarlyWarningOperationButton(this HtmlHelper helper, string url, EarlyWarningConstants.Operation operation, string text = "", string ccsClass = "", string dataButtontype = "", string id = "")
        {
            var constants = new EarlyWarningConstants();
            var ewCache   = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.EarlyWarning);

            // If cache is null then force the user to sign-in again
            if (null == ewCache)
            {
                Signout();
                return(MvcHtmlString.Create(string.Empty));
            }

            var html = string.Empty;

            if (ewCache.CheckAccess(constants.ItemName(operation), DateTime.Now) == AuthorizationType.Allow)
            {
                html = "<a href=" + url;
                if (ccsClass != "")
                {
                    html += " class=" + ccsClass;
                }
                if (id != "")
                {
                    html += " id=" + id;
                }
                if (dataButtontype != "")
                {
                    html += " data-buttontype=" + dataButtontype;
                }
                if (text != "")
                {
                    html += " >" + text + "</a>";
                }
                else
                {
                    html += " ></a>";
                }
            }
            return(MvcHtmlString.Create(html));
        }
示例#11
0
        public static MvcHtmlString AdminOperationButton(this HtmlHelper helper, string url, string text = "", string ccsClass = "", string dataButtontype = "", string id = "")
        {
            var ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Finance);

            string html = string.Empty;

            // If cache is null then force the user to sign-in again
            if (null == ewCache)
            {
                Signout();
                return(MvcHtmlString.Create(string.Empty));
            }
            else
            {
                html = "<a href=" + url;
                if (ccsClass != "")
                {
                    html += " class=" + ccsClass;
                }
                if (id != "")
                {
                    html += " id=" + id;
                }
                if (dataButtontype != "")
                {
                    html += " data-buttontype=" + dataButtontype;
                }
                if (text != "")
                {
                    html += " >" + text + "</a>";
                }
                else
                {
                    html += " ></a>";
                }
            }
            return(MvcHtmlString.Create(html));
        }
示例#12
0
 public ProcurementAuthorize()
 {
     ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Procurement);
 }
示例#13
0
 public PSNPAuthorize()
 {
     ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.PSNP);
 }
示例#14
0
 public EarlyWarningAuthorize()
 {
     ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.EarlyWarning);
 }
示例#15
0
 public LogisticsAuthorize()
 {
     ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Logistics);
 }
示例#16
0
        //public static int GetUnreadNotifications()
        //{
        //    try
        //    {

        //        var user = HttpContext.Current.User.Identity.Name;
        //        var app = GetApplication(user);

        //        var notificationService = (INotificationService)DependencyResolver.Current.GetService(typeof(INotificationService));
        //        var totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
        //        return totallUnread.Count();
        //    }
        //    catch (Exception)
        //    {
        //        return 0;
        //    }
        //}

        public static HtmlString GetActiveNotifications(this HtmlHelper helper, bool isOldTheme = true)
        {
            try
            {
                var user = HttpContext.Current.User.Identity.Name;
                var notificationService = (INotificationService)DependencyResolver.Current.GetService(typeof(INotificationService));

                List <Cats.Models.Notification> totallUnread = null;
                var currentUser = UserAccountHelper.GetUser(user);
                var app         = GetApplication(user);

                if (app == Models.Constant.Application.HUB)
                {
                    totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && n.Id == currentUser.DefaultHub && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
                }
                else if (app == Models.Constant.Application.REGIONAL)
                {
                    totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && n.Id == currentUser.RegionID && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
                }
                else
                {
                    totallUnread = notificationService.GetAllNotification().Where(n => n.IsRead == false && app.Contains(n.Application)).OrderByDescending(n => n.NotificationId).ToList();
                }



                var str = "<ul class='dropdown-menu-list scroller'>";


                int max = 0;

                if (totallUnread.Count < 1)
                {
                    return(MvcHtmlString.Create(""));
                }
                max = totallUnread.Count > 5 ? 5 : totallUnread.Count;

                for (int i = 0; i < max; i++)
                {
                    str = str + "<li>";
                    // str = str + "<a href=" + totallUnread[i].Url + ">";
                    str = str + "<a style='padding: 10px 5px' href=" + GetRelativeURL(totallUnread[i].Url) + ">";
                    str = str + totallUnread[i].Text;
                    str = str + "</li>";
                    str = str + "</a>";
                }

                str = str + "</ul>";
                if (totallUnread.Count > 5 && isOldTheme)
                {
                    var webAppDir = (HttpContext.Current.Request.ApplicationPath == "/") ? "" : HttpContext.Current.Request.ApplicationPath;
                    str += "<a href='" + webAppDir + "/Home/GetUnreadNotificationDetail'> View More </a>";
                }

                return(MvcHtmlString.Create(str));
            }
            catch (Exception)
            {
                return(MvcHtmlString.Create(""));
            }
        }
示例#17
0
文件: DateHelpers.cs 项目: IYoni/cats
        //public static string ToCTSPreferedDateFormat(this Nullable<DateTime> date, string lang)
        //{
        //    if (date != null)
        //    {
        //        DateTime d = date;

        //        if (lang.ToLower() == "gc")
        //        {
        //            IFormatProvider provider = new CultureInfo("en-GB");
        //            return d.ToString("dd-MMM-yyyy", provider);
        //        }
        //        else
        //        {
        //            EthiopianDate ethiopianDate = new EthiopianDate(date);
        //            return ethiopianDate.ToLongDateString();
        //        }
        //    }
        //    else
        //    {
        //        return String.Empty;
        //    }
        //}

        public static string CTSPreferedDateLabel(this string label)
        {
            return(string.Format("{0}( {1})", label, UserAccountHelper.UserCalendarPreference()));
        }
示例#18
0
        public static string AmharicReportList()
        {
            var html        = string.Empty;
            var userName    = System.Configuration.ConfigurationManager.AppSettings["CatsReportUserName"];
            var password    = System.Configuration.ConfigurationManager.AppSettings["CatsReportPassword"];
            var user        = (UserIdentity)HttpContext.Current.User.Identity;
            var role        = UserRoleHelper.GetUserRole(user.Profile.UserName);
            var lang        = user.Profile.LanguageCode;
            var currentUser = UserAccountHelper.GetCurrentUser();

            try
            {
                var rs = new ReportingService2010
                {
                    Credentials = new NetworkCredential(userName, password)
                };

                //var folders = rs.ListChildren("/", false);
                ////html += "<ul class='dropdown-menu'>";
                //foreach (var folder in folders)
                //{
                //if (folder.TypeName == "Folder" && folder.Name != "Data Sources" && folder.Name != "Datasets")
                //{
                var reports = new CatalogItem[100];
                if (currentUser.RegionalUser)
                {
                    reports = rs.ListChildren("/Regional/AM", false);
                }
                else if (currentUser.DefaultHub != null)
                {
                    reports = rs.ListChildren("/Hub/AM", false);
                }
                else if (currentUser.CaseTeam != null)
                {
                    switch (currentUser.CaseTeam)
                    {
                    case (int)UserType.CASETEAM.EARLYWARNING:
                        reports = rs.ListChildren("/Early Warning/AM", false);
                        break;

                    case (int)UserType.CASETEAM.PSNP:
                        reports = rs.ListChildren("/FSCD/AM", false);
                        break;

                    case (int)UserType.CASETEAM.LOGISTICS:
                        reports = rs.ListChildren("/Logistics/AM", false);
                        break;

                    case (int)UserType.CASETEAM.PROCUREMENT:
                        reports = rs.ListChildren("/Procurement/AM", false);
                        break;

                    case (int)UserType.CASETEAM.FINANCE:
                        reports = rs.ListChildren("/Finance/AM", false);
                        break;
                    }
                }

                //html += "<li class='dropdown-submenu'>";
                //html += "<a href='#' data-toggle='dropdown'>" + folder.Name + "</a>";
                //html += "<ul class='dropdown-menu'>";
                //html += "<div> <table class='table table-bordered'>  <thead>  <tr>  <th>Report</th>  <th>Description</th>  </tr>  </thead>  <tbody>";
                //html += "<div id='list8'><ul>";
                html += "<div> <ul>";
                foreach (var report in reports)
                {
                    html += "<li>";
                    var baseUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/";
                    html += "<a class='AMreportLink'  data-toggle='tooltip' data-placement='bottom' rel='tooltip'  title='" + report.Description + "' data-reportpath='" + report.Path + "' href=' " + baseUrl + "AmharicReportViewer.aspx?path=" + report.Path + "'>" + report.Name + "</a>";
                    //var desc = report.Description;
                    html += "</li>";
                }
                html += "</ul></div>";
                //html += "</tbody> </table> </div>";
                //}
                //}
                //html += "</ul>";
            }
            catch (Exception ex)
            {
                html = "";
            }

            return(html);
        }
示例#19
0
 public RegionalAuthorize()
 {
     ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Region);
 }