Beispiel #1
0
        public tbl_menu_access Assignmenu(string userid)
        {
            var user          = _userRepository.GetSingleByUsername(userid);
            var newmenuaccess = new tbl_menu_access();

            if (user != null)
            {
                var menulist = _menuRepository.GetAll().ToList();
                foreach (var menu in menulist)
                {
                    if (user.tenant_id == 1)
                    {
                        newmenuaccess = new tbl_menu_access()
                        {
                            menu_id   = menu.id,
                            user_id   = user.id,
                            tenant_id = user.tenant_id,
                            is_active = true
                        };
                        _menuaccessRepository.Add(newmenuaccess);
                        _unitOfWork.Commit();
                    }
                    else
                    {
                        if (menu.parent_menu != 3 && menu.menu_order != 3)
                        {
                            newmenuaccess = new tbl_menu_access()
                            {
                                menu_id   = menu.id,
                                user_id   = user.id,
                                tenant_id = user.tenant_id,
                                is_active = true
                            };
                            _menuaccessRepository.Add(newmenuaccess);
                            _unitOfWork.Commit();
                        }
                    }

                    //else
                    //{
                    //    if (menu.name != "Projects")
                    //    {
                    //        if (menu.parent_menu != 3)
                    //        {
                    //            newmenuaccess = new tbl_menu_access()
                    //            {
                    //                menu_id = menu.id,
                    //                user_id = user.id,
                    //                tenant_id = user.tenant_id,
                    //                is_active = true
                    //            };
                    //            _menuaccessRepository.Add(newmenuaccess);
                    //            _unitOfWork.Commit();
                    //        }
                    //    }
                    //}
                }
            }
            return(newmenuaccess);
        }
        public HttpResponseMessage SaveMenuAccess(HttpRequestMessage request, List <MenuAccessViewModel> userAccessList)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, new { success = false });
                }
                else
                {
                    //Removing Menu Access
                    int tenantid = userAccessList[0].tenant_id;
                    int userid = userAccessList[0].user_id;

                    var rMenuAccess = _menuaccessRepository.GetAll().Where(x => x.tenant_id == tenantid && x.user_id == userid);
                    if (rMenuAccess != null)
                    {
                        foreach (var menu in rMenuAccess)
                        {
                            menu.is_active = false;
                            _menuaccessRepository.Edit(menu);
                        }
                    }

                    for (int i = 0; i < userAccessList.Count; i++)
                    {
                        var menuAccess = _menuaccessRepository.GetSingleMenuAccess(userAccessList[i].tenant_id, userAccessList[i].user_id, userAccessList[i].menu_id);
                        if (menuAccess == null)
                        {
                            //Add
                            var newAccess = new tbl_menu_access()
                            {
                                menu_id = userAccessList[i].menu_id,
                                user_id = userAccessList[i].user_id,
                                tenant_id = userAccessList[i].tenant_id,
                                is_active = true,
                            };
                            _menuaccessRepository.Add(newAccess);
                        }
                        else
                        {
                            //update
                            menuAccess.is_active = true;
                            _menuaccessRepository.Edit(menuAccess);
                        }
                        _unitOfWork.Commit();
                    }
                    response = request.CreateResponse(HttpStatusCode.OK, new { success = true });
                }
                return response;
            }));
        }