Exemple #1
0
        public ActionResult ConfigEquipIndex()
        {
            var vm = new ConfigViewModel();

            string actionName = "ConfigEquipIndex";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");

            try
            {
                SessionKeys.LoadTablesInSession(SessionKeys.ApplicableUnits, "", "");


                vm._tbl_Unit = ((List <ClassLibrary.Models.tbl_Unit>)Session[SessionKeys.ApplicableUnits]);

                vm.selectedData = "0";

                using (var db = new WebAppDbContext())
                {
                    vm.tbl_Parts_list = db.tbl_Parts.Where(x => x.Status == "Active" && (x.PartTypeID == "X" || x.PartTypeID == "A")).ToList();
                    vm._M_PMS         = db.M_PMS.ToList();
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }

            _logger.Log(LogLevel.Trace, actionName + " :: Ended.");

            return(View("ConfigEquipIndex", vm));
        }
Exemple #2
0
        public ActionResult Create(tbl_Cage tbl_Cage)
        {
            string actionName = "Create";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");

            try
            {
                if (ModelState.IsValid)
                {
                    using (var db = new WebAppDbContext())
                    {
                        if (!db.tbl_Cage.Any(x => x.CageCode == tbl_Cage.CageCode))
                        {
                            // Get Current user Id
                            var userId = Session[SessionKeys.UserId]?.ToString();
                            tbl_Cage.CreatedByUser  = userId;
                            tbl_Cage.ModifiedByUser = userId;

                            //Get Current Date & Time.
                            tbl_Cage.CreatedOnDate  = DateTime.Now;
                            tbl_Cage.ModifiedOnDate = DateTime.Now;
                            tbl_Cage.Status         = "Active";

                            db.tbl_Cage.Add(tbl_Cage);
                            db.SaveChanges();


                            Alert("Record Added Successfully !! ", NotificationType.success);
                        }
                        else
                        {
                            _logger.Log(LogLevel.Trace, actionName + " :: Cage code : " + tbl_Cage.CageCode + " already exist.");
                            Alert("Cage code already exist.", NotificationType.error);
                        }
                    }
                }
                else
                {
                    CageViewModels vm = new CageViewModels();

                    SessionKeys.LoadTablesInSession(SessionKeys.Countries, "", "");
                    vm._tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]);

                    _logger.Log(LogLevel.Trace, actionName + " :: Model state not valid.");
                    return(PartialView("_Create", vm));
                }
            }
            catch (Exception ex)
            {
                Alert("Their is something went wrong!!!", NotificationType.error);
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
                Exception(ex);
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");

            return(RedirectToAction("Index"));
        }
Exemple #3
0
        private bool LoadRole(string roleId)
        {
            string actionName = "LoadRole";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");

            bool response = false;

            try
            {
                if (!String.IsNullOrWhiteSpace(roleId))
                {
                    List <PermissionViewModel> ListPermissionViewModel = new List <PermissionViewModel>();

                    using (Entities _context = new Entities())
                    {
                        var loginId     = Session[SessionKeys.UserId].ToString();
                        var currentRole = _context.tbl_UserRole.Where(x => x.UserId == loginId && x.RoleId == roleId && x.IsDeleted != 1 && x.IsActive != 0)?.FirstOrDefault().RoleId;

                        if (!string.IsNullOrWhiteSpace(currentRole))
                        {
                            SessionKeys.LoadTablesInSession(SessionKeys.ReloadRolePermissions, "", currentRole);
                            var permissions = ((List <tbl_Permission>)Session[SessionKeys.RolePermissions]);

                            foreach (var item in permissions)
                            {
                                PermissionViewModel permissionViewModel = new PermissionViewModel()
                                {
                                    PermissionId = item.PermissionId,
                                    DisplayName  = item.DisplayName,
                                    Level        = item.PermissionLevel.ToString(),
                                    ParentId     = item.ParentId,
                                    URL          = item.URL
                                };

                                ListPermissionViewModel.Add(permissionViewModel);
                            }

                            Session[SessionKeys.SessionHelperInstance] = ((SessionHelper)Session[SessionKeys.SessionHelperInstance]).UpdateFields(roleId, ListPermissionViewModel);

                            response = true;
                        }
                        else
                        {
                            // Show some error
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " :: Exception : " + ex.ToString());
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");
            return(response);
        }
Exemple #4
0
 private CageViewModels GetCage(int id)
 {
     SessionKeys.LoadTablesInSession(SessionKeys.Countries);
     using (var db = new WebAppDbContext())
     {
         var viewModel = new CageViewModels()
         {
             tbl_Cage     = db.tbl_Cage.FirstOrDefault(x => x.CageId == id),
             _tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]),
         };
         return(viewModel);
     }
 }
Exemple #5
0
        public ActionResult Create()
        {
            string actionName = "Create";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");
            CageViewModels vm = new CageViewModels();

            try
            {
                SessionKeys.LoadTablesInSession(SessionKeys.Countries, "", "");
                vm._tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");
            return(PartialView("_Create", vm));
        }
Exemple #6
0
        public ActionResult Index()
        {
            string actionName = "Index";

            _logger.Log(LogLevel.Error, actionName + " :: started.");

            var vm = new ConfigViewModel();

            try
            {
                SessionKeys.LoadTablesInSession(SessionKeys.AllUnits, "", "");
                vm._tbl_Unit = ((List <ClassLibrary.Models.tbl_Unit>)Session[SessionKeys.AllUnits]);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }

            _logger.Log(LogLevel.Error, actionName + " :: Ended.");

            return(View("Index", vm));
        }
Exemple #7
0
        private bool PopulateSessions()
        {
            bool   response   = false;
            string actionName = "PopulateSessions";

            try
            {
                _logger.Log(LogLevel.Trace, actionName + " :: started.");

                SessionKeys.LoadTablesInSession(SessionKeys.AllUnits);
                SessionKeys.LoadTablesInSession(SessionKeys.UnitTypes);

                if (Session[SessionKeys.UserId] != null)
                {
                    var userId = Session[SessionKeys.UserId]?.ToString();

                    using (Entities _context = new Entities())
                    {
                        var data = _context.tbl_User.Where(x => x.UserId == userId && x.IsActive != 0 && x.IsDeleted != 1).FirstOrDefault();

                        if (data != null)
                        {
                            Session[SessionKeys.UserUnitId] = data.UnitId;

                            var allUnits = ((List <ClassLibrary.Models.tbl_Unit>)Session[SessionKeys.AllUnits]);
                            var unit     = allUnits.Where(x => x.Id == data.UnitId).FirstOrDefault();

                            if (unit != null && unit.UnitTypeId != null)
                            {
                                var unitLevel = ((List <ClassLibrary.Models.tbl_UnitType>)Session[SessionKeys.UnitTypes]).Where(x => x.UnitTypeId == unit.UnitTypeId).Select(x => x.UnitTypeLevel).FirstOrDefault();

                                IEnumerable <ClassLibrary.Models.tbl_Unit> UnitList;

                                if (unitLevel == 0)
                                {
                                    UnitList = allUnits;
                                }
                                else if (unitLevel == 1)
                                {
                                    var lookup = allUnits.ToLookup(x => x.ParentUnitId);
                                    var res    = lookup[data.UnitId].SelectRecursive(x => lookup[x.Id]).ToList();
                                    res.Add(unit);
                                    UnitList = res;
                                }
                                else
                                {
                                    UnitList = allUnits.Where(x => x.Id == data.UnitId).ToList();
                                }

                                Session[SessionKeys.ApplicableUnits] = UnitList;

                                response = true;
                            }
                            else
                            {
                                _logger.Log(LogLevel.Error, actionName + " :: Ended.. Unit Id : " + data.UnitId + " not found.");
                                RedirectToAction("Login", "Account");
                            }
                        }
                        else
                        {
                            _logger.Log(LogLevel.Error, actionName + " ::  Ended.. User not found.");
                            RedirectToAction("Login", "Account");
                        }
                    }
                }
                else
                {
                    _logger.Log(LogLevel.Error, actionName + " :: Ended.. session user is null or empty.");
                    RedirectToAction("Login", "Account");
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }
            _logger.Log(LogLevel.Trace, actionName + " :: ended.");

            return(response);
        }
Exemple #8
0
        public ActionResult Dashboard()
        {
            string actionName = "Dashboard";
            string inRoleId   = ((SessionHelper)Session[SessionKeys.SessionHelperInstance])?.CurrentRoleId;

            try
            {
                string siteId = Session[SessionKeys.UserUnitId]?.ToString();

                _logger.Log(LogLevel.Trace, actionName + " :: started.");

                if (!string.IsNullOrWhiteSpace(siteId))
                {
                    if (Regex.IsMatch(siteId, RegexHelper.NumberOnly))
                    {
                        var applicableUnits = ((List <ClassLibrary.Models.tbl_Unit>)Session[SessionKeys.ApplicableUnits]);
                        int intSiteId       = Convert.ToInt32(siteId);

                        if (applicableUnits != null && applicableUnits.Where(x => x.Id == intSiteId).Any())
                        {
                            DashboardViewModel         dashboard = new DashboardViewModel();
                            List <PermissionViewModel> ListPermissionViewModel = new List <PermissionViewModel>();

                            dashboard._tbl_Unit = ((List <ClassLibrary.Models.tbl_Unit>)Session[SessionKeys.AllUnits]);

                            string defaultRoleId = !String.IsNullOrWhiteSpace(inRoleId) ? inRoleId : string.Empty;

                            dashboard.datetime = DateTime.Now.ToString();
                            string loginUserId = Session[SessionKeys.UserId]?.ToString();

                            using (Entities _context = new Entities())
                            {
                                if (string.IsNullOrWhiteSpace(defaultRoleId))
                                {
                                    defaultRoleId = _context.tbl_UserRole.Where(x => x.UserId == loginUserId && x.IsDefault == 1 && x.IsActive != 0 && x.IsDeleted != 1)?.FirstOrDefault().RoleId;
                                }
                                else
                                {
                                    defaultRoleId = _context.tbl_UserRole.Where(x => x.UserId == loginUserId && x.RoleId == inRoleId && x.IsActive != 0 && x.IsDeleted != 1)?.FirstOrDefault().RoleId;
                                }

                                if (!String.IsNullOrWhiteSpace(defaultRoleId))
                                {
                                    SessionKeys.LoadTablesInSession(SessionKeys.RolePermissions, "", defaultRoleId);
                                    var permissions = ((List <tbl_Permission>)Session[SessionKeys.RolePermissions]);

                                    foreach (var item in permissions)
                                    {
                                        PermissionViewModel permissionViewModel = new PermissionViewModel()
                                        {
                                            PermissionId = item.PermissionId,
                                            DisplayName  = item.DisplayName,
                                            Level        = item.PermissionLevel?.ToString(),
                                            ParentId     = item.ParentId,
                                            URL          = item.URL,
                                            IconPath     = item.IconPath
                                        };

                                        ListPermissionViewModel.Add(permissionViewModel);
                                    }

                                    Session[SessionKeys.SessionHelperInstance] = new SessionHelper(loginUserId, defaultRoleId, ListPermissionViewModel);
                                    dashboard.DashboardId = GetDashboardId(loginUserId);


                                    return(View(dashboard));
                                }
                                else
                                {
                                    _logger.Log(LogLevel.Error, actionName + " :: Role id not found.");
                                }
                            }
                        }
                        else
                        {
                            _logger.Log(LogLevel.Error, actionName + " :: Please select valid site id.");
                        }
                    }
                    else
                    {
                        _logger.Log(LogLevel.Error, actionName + " :: Invalid input in site id.");
                    }
                }
                else
                {
                    _logger.Log(LogLevel.Error, actionName + " :: Site id empty.");
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }
            return(RedirectToAction("UnitSelection"));
        }