Exemplo n.º 1
0
        public JsonResult SaveUserPermission(decimal[] id, string userId)
        {
            //userActionMappingFactory = new UserActionMappingFactory();
            //actionFactory = new ActionFactory();
            try
            {
                List <tblAction> actions = new List <tblAction>();
                actions = unitOfWork.ActionRepository.Get().ToList();

                List <tblUserActionMapping> actionMappings = new List <tblUserActionMapping>();
                actionMappings = unitOfWork.UserActonMappingRepository.Get().Where(a => a.user_id == userId).ToList();

                foreach (var items in actionMappings)
                {
                    unitOfWork.UserActonMappingRepository.Delete(items);
                }

                if (id != null)
                {
                    foreach (var items in id)
                    {
                        tblUserActionMapping actionMapping = new tblUserActionMapping();
                        actionMapping.action_id     = Int32.Parse(items.ToString());
                        actionMapping.user_id       = userId;
                        actionMapping.is_permitted  = 1;
                        actionMapping.restaurant_id = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                        unitOfWork.UserActonMappingRepository.Insert(actionMapping);
                        //var selectedAction = actions.Where(a => a.id == items).FirstOrDefault();
                        //if (selectedAction != null)
                        //{
                        //    var hidenactions =
                        //        actions.Where(ha => ha.class_name == selectedAction.class_name && ha.id != items);
                        //    foreach (var hidenAction in hidenactions)
                        //    {
                        //        tblUserActionMapping hactionMapping = new tblUserActionMapping();
                        //        hactionMapping.action_id = hidenAction.id;
                        //        hactionMapping.user_id = userId;
                        //        hactionMapping.is_permitted = 1;
                        //        hactionMapping.membership_id = SessionManger.BrokerOfLoggedInUser(Session).membership_id;
                        //        userActionMappingFactory.Add(hactionMapping);
                        //    }
                        //}
                    }
                }
                unitOfWork.Save();

                return(Json(new { success = true, errorMessage = "Mapped Successfully" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult SaveUserPermission(decimal[] id, string userId)
        {
            //userActionMappingFactory = new UserActionMappingFactory();
            //actionFactory = new ActionFactory();
            try
            {
                List <tblAction> actions = new List <tblAction>();
                actions = unitOfWork.ActionRepository.Get().ToList();

                List <tblUserActionMapping> actionMappings = new List <tblUserActionMapping>();
                actionMappings = unitOfWork.UserActonMappingRepository.Get().Where(a => a.user_id == userId).ToList();

                foreach (var items in actionMappings)
                {
                    unitOfWork.UserActonMappingRepository.Delete(items);
                }

                if (id != null)
                {
                    foreach (var items in id)
                    {
                        tblUserActionMapping actionMapping = new tblUserActionMapping();
                        actionMapping.action_id       = Int32.Parse(items.ToString());
                        actionMapping.user_id         = userId;
                        actionMapping.is_permitted    = 1;
                        actionMapping.WorkShopId      = Int32.Parse(SessionManger.WorkShopOfLoggedInUser(Session).ToString());
                        actionMapping.CreatedBy       = SessionManger.LoggedInUser(Session);
                        actionMapping.CreatedDateTime = DateTime.Now;
                        actionMapping.EditedBy        = null;
                        actionMapping.EditedDateTime  = null;
                        unitOfWork.UserActonMappingRepository.Insert(actionMapping);
                    }
                }
                unitOfWork.Save();

                return(Json(new { success = true, successMessage = "Mapped Successfully" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }