private void EditConfirmResponseHandler(MsgBxResultMessage obj)
        {
            if (obj.Result == eMessageBoxResult.Yes)
            {
                //Edit Code
                SelectedRole.ParentRoleId = SelectedRole.ParentRole.Id;
                SelectedRole.ParentRole   = null;
                string jsonObj     = JsonConvert.SerializeObject(SelectedRole);
                var    httpContent = new StringContent(jsonObj, Encoding.UTF8, "application/json");
                var    response    = HttpManager.Instance.Post(httpContent, APIPaths.RoleUpdate);
                ActionResult <OrgRoleDTO> actionResult = JsonConvert.DeserializeObject <ActionResult <OrgRoleDTO> >(response);
                if (actionResult.ReturnCode == eReturnCode.Success)
                {
                    ShowMessageBox(eMessageBoxType.Info, Application.Current.MainWindow.Resources["txtMsgTitleSuccess"].ToString(),
                                   Application.Current.MainWindow.Resources["txtMsgTextRoleEditSuccess"].ToString());
                }
                else
                {
                    ShowMessageBox(eMessageBoxType.Error, Application.Current.MainWindow.Resources["txtMsgTitleError"].ToString(),
                                   Application.Current.MainWindow.Resources["txtMsgTextRoleEditError"].ToString());
                }
                FetchData();
                SelectedRole            = new OrgRoleDTO();
                SelectedRole.ParentRole = AllRoles.Where(r => r.ParentRoleId == 0).FirstOrDefault().Clone() as OrgRoleDTO;
                RaisePropertyChanged("SelectedRole");
            }


            SelectedRole            = new OrgRoleDTO();
            SelectedRole.ParentRole = AllRoles.Where(r => r.ParentRoleId == 0).FirstOrDefault().Clone() as OrgRoleDTO;
            RaisePropertyChanged("SelectedRole");
            Messenger.Default.Unregister <MsgBxResultMessage>(this, DeleteConfirmResponseHandler);
        }
        private void SaveCommandHandler()
        {
            AppLogger.Instance.LogBegin(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
            try
            {
                if (!_isEdit)
                {
                    //Add Code
                    SelectedRole.ParentRoleId = SelectedRole.ParentRole.Id;
                    SelectedRole.ParentRole   = null;
                    string jsonObj     = JsonConvert.SerializeObject(SelectedRole);
                    var    httpContent = new StringContent(jsonObj, Encoding.UTF8, "application/json");
                    var    response    = HttpManager.Instance.Post(httpContent, APIPaths.RoleCreate);
                    ActionResult <OrgRoleDTO> actionResult = JsonConvert.DeserializeObject <ActionResult <OrgRoleDTO> >(response);
                    if (actionResult.ReturnCode == eReturnCode.Success)
                    {
                        ShowMessageBox(eMessageBoxType.Info, Application.Current.MainWindow.Resources["txtMsgTitleSuccess"].ToString(),
                                       Application.Current.MainWindow.Resources["txtMsgTextRoleAddSuccess"].ToString());
                    }
                    else
                    {
                        ShowMessageBox(eMessageBoxType.Error, Application.Current.MainWindow.Resources["txtMsgTitleError"].ToString(),
                                       Application.Current.MainWindow.Resources["txtMsgTextRoleAddError"].ToString());
                    }
                    FetchData();

                    SelectedRole            = new OrgRoleDTO();
                    SelectedRole.ParentRole = AllRoles.Where(r => r.ParentRoleId == 0).FirstOrDefault().Clone() as OrgRoleDTO;
                    RaisePropertyChanged("SelectedRole");
                }
                else
                {
                    if (SelectedRole.Id == SelectedRole.ParentRole.Id)
                    {
                        ShowMessageBox(eMessageBoxType.Error, Application.Current.MainWindow.Resources["txtMsgTitleError"].ToString(),
                                       Application.Current.MainWindow.Resources["txtMsgTextParentRoleModifiedToSelf"].ToString());
                        return;
                    }

                    if (!ValidateRoleEdit(SelectedRole.ParentRole))
                    {
                        ShowMessageBox(eMessageBoxType.Error, Application.Current.MainWindow.Resources["txtMsgTitleError"].ToString(),
                                       Application.Current.MainWindow.Resources["txtMsgTextParentRoleModifiedToSelf"].ToString());
                        return;
                    }
                    Messenger.Default.Register <MsgBxResultMessage>(this, EditConfirmResponseHandler);
                    ShowMessageBox(eMessageBoxType.Confirmation, Application.Current.MainWindow.Resources["txtMsgTitleConfirm"].ToString(),
                                   Application.Current.MainWindow.Resources["txtMsgTextRoleEditConfirm"].ToString());
                    return;
                }
            }
            catch (Exception ex)
            {
                AppLogger.Instance.Log(eLogType.Error, ex.ToString());
            }
            finally
            {
                AppLogger.Instance.LogEnd(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
            }
        }
Beispiel #3
0
        public ActionResult <string> Update(OrgRoleDTO orgRoleDTO)
        {
            AppLogger.Instance.LogBegin(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
            try
            {
                OrgRole orgRole = _orgRoles.Where(e => e.Id == orgRoleDTO.Id).FirstOrDefault();

                if (orgRole != null)
                {
                    orgRole.Name         = orgRoleDTO.Name;
                    orgRole.Description  = orgRoleDTO.Description;
                    orgRole.ParentRoleId = orgRoleDTO.ParentRoleId;
                    _appDBContext.SaveChanges();
                }
                return(new ActionResult <string>()
                {
                    ReturnCode = eReturnCode.Success, ReturnDescription = "Role updated successfully", Result = ""
                });
            }
            catch (Exception ex)
            {
                AppLogger.Instance.Log(eLogType.Error, ex.ToString());
                return(new ActionResult <string>()
                {
                    ReturnCode = eReturnCode.Failure, ReturnDescription = "Role updated successfully", Result = ""
                });
            }
            finally
            {
                AppLogger.Instance.LogEnd(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
            }
        }
 private OrgRoleDTO CreateChild(OrgRoleDTO role)
 {
     AppLogger.Instance.LogBegin(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     try
     {
         if (role.ChildRoles.Count > 0)
         {
             var childRoles = (from subRole in AllRoles where subRole.ParentRoleId == role.Id select subRole).ToList();
             foreach (OrgRoleDTO childRole in childRoles)
             {
                 CreateChild(childRole);
             }
             if (childRoles.Count > 0)
             {
                 role.ChildRoles = childRoles;
             }
         }
         return(role);
     }
     catch (Exception ex)
     {
         AppLogger.Instance.Log(eLogType.Error, ex.ToString());
         return(null);
     }
     finally
     {
         AppLogger.Instance.LogEnd(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     }
 }
        private static void AddCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            RoleSelector ms = sender as RoleSelector;

            ms.ExecuteSelctionChangedCallBack = false;
            ObservableCollection <MultiSelectItem <OrgRoleDTO> > tempSelecItems = ms.GetValue(SelectionListProperty) as ObservableCollection <MultiSelectItem <OrgRoleDTO> >;
            OrgRoleDTO LastItem = tempSelecItems[tempSelecItems.Count - 2].CurrentItem;

            if (LastItem != null)
            {
                MultiSelectItem <OrgRoleDTO> tempSelction = new MultiSelectItem <OrgRoleDTO>()
                {
                    Items       = new ObservableCollection <OrgRoleDTO>(LastItem.ChildRoles),
                    CurrentItem = LastItem.ChildRoles.First()
                };
                tempSelecItems.Insert(tempSelecItems.Count - 1, tempSelction);
                ms.SetValue(SelectionProperty, LastItem.ChildRoles.First());
                if (tempSelction.CurrentItem.ChildRoles.Count == 0)
                {
                    tempSelecItems.RemoveAt(tempSelecItems.Count - 1);
                }
                ms.SetValue(SelectionListProperty, tempSelecItems);
            }
            ms.ExecuteSelctionChangedCallBack = true;
        }
Beispiel #6
0
 public ActionResult <OrgRoleDTO> Add(OrgRoleDTO roleDTO)
 {
     AppLogger.Instance.LogBegin(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     try
     {
         OrgRole orgRoleModel = ModelFactory.Instance.CreateModel(roleDTO);
         _orgRoles.Add(orgRoleModel);
         _appDBContext.SaveChanges();
         return(new ActionResult <OrgRoleDTO>()
         {
             ReturnCode = eReturnCode.Success,
             ReturnDescription = "Role added successfully",
             Result = ModelFactory.Instance.CreateDTO(orgRoleModel)
         });
     }
     catch (Exception ex)
     {
         AppLogger.Instance.Log(eLogType.Error, ex.ToString());
         return(new ActionResult <OrgRoleDTO>()
         {
             ReturnCode = eReturnCode.Failure, ReturnDescription = "Role add error"
         });
     }
     finally
     {
         AppLogger.Instance.LogEnd(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     }
 }
        private static void RemoveCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            RoleSelector ms = sender as RoleSelector;

            ms.ExecuteSelctionChangedCallBack = false;
            OrgRoleDTO param = e.Parameter as OrgRoleDTO;

            if (param.ParentRoleId == 0)
            {
                return;
            }
            ObservableCollection <MultiSelectItem <OrgRoleDTO> > tempSelecItems = ms.GetValue(SelectionListProperty) as ObservableCollection <MultiSelectItem <OrgRoleDTO> >;
            var removedItem      = tempSelecItems.ToList().Where(item => item.CurrentItem.Id == param.Id).First();
            int removedItemIndex = tempSelecItems.IndexOf(removedItem);

            for (int i = removedItemIndex; i < tempSelecItems.Count;)
            {
                tempSelecItems.RemoveAt(i);
            }
            ms.SetValue(SelectionProperty, tempSelecItems.Last().CurrentItem);
            if (tempSelecItems.Last().CurrentItem.ChildRoles.Count > 0)
            {
                tempSelecItems.Add(new MultiSelectItem <OrgRoleDTO>()
                {
                    IsButton = true
                });
            }
            ms.SetValue(SelectionListProperty, tempSelecItems);
            ms.ExecuteSelctionChangedCallBack = true;
        }
Beispiel #8
0
 public ActionResult <OrgRoleDTO> Get(string name)
 {
     AppLogger.Instance.LogBegin(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     try
     {
         OrgRole    role    = _orgRoles.Where(e => e.Name == name).FirstOrDefault();
         OrgRoleDTO roleDTO = null;
         if (role != null)
         {
             roleDTO = ModelFactory.Instance.CreateDTO(role);
         }
         return(new ActionResult <OrgRoleDTO>()
         {
             ReturnCode = eReturnCode.Success, ReturnDescription = "Role get success", Result = roleDTO
         });
     }
     catch (Exception ex)
     {
         AppLogger.Instance.Log(eLogType.Error, ex.ToString());
         return(new ActionResult <OrgRoleDTO>()
         {
             ReturnCode = eReturnCode.Success, ReturnDescription = "Role get error"
         });
     }
     finally
     {
         AppLogger.Instance.LogEnd(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     }
 }
Beispiel #9
0
        public IHttpActionResult Delete(OrgRoleDTO roleDTO)
        {
            AppLogger.Instance.LogBegin(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
            iRoleRepository = new OrgRoleRepository(this.Request.GetOwinContext().Get <AppDBContext>());
            ActionResult <string> actionResult = iRoleRepository.Delete(roleDTO.Id);

            AppLogger.Instance.LogEnd(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
            return(Ok(actionResult));
        }
        private void ConstructTree()
        {
            OrgRoleDTO rootNode = (from role in AllRoles where role.ParentRoleId == 0 select role).FirstOrDefault();

            CreateChild(rootNode);
            TreeData = new ObservableCollection <OrgRoleDTO>();
            TreeData.Add(rootNode);
            RaisePropertyChanged("TreeData");
        }
Beispiel #11
0
 public OrgRole CreateModel(OrgRoleDTO orgRoleDTO)
 {
     return(new OrgRole()
     {
         Id = orgRoleDTO.Id,
         Description = orgRoleDTO.Description,
         Name = orgRoleDTO.Name,
         ParentRole = orgRoleDTO.ParentRole == null ? null: CreateModel(orgRoleDTO.ParentRole),
         ParentRoleId = orgRoleDTO.ParentRoleId,
         ChildRoles = orgRoleDTO.ChildRoles.ToList().Select(sub => CreateModel(sub)).ToList()
     });
 }
        private bool ValidateRoleEdit(OrgRoleDTO role)
        {
            bool returnVal = true;

            if (role.Id == SelectedRole.Id)
            {
                return(false);
            }
            if (role.ParentRole != null)
            {
                returnVal = returnVal == true?ValidateRoleEdit(role.ParentRole) : returnVal;
            }
            return(returnVal);
        }
        public RoleViewModel()
        {
            InitializeCommands();

            GridDisplaySelected = true;
            RaisePropertyChanged("GridDisplaySelected");
            PageTitle = Application.Current.MainWindow.Resources["txtAddRole"].ToString();
            RaisePropertyChanged("PageTitle");

            SelectedRole = new OrgRoleDTO();
            RaisePropertyChanged("SelectedRole");
            ThreadStart ts = new ThreadStart(FetchData);
            Thread      t  = new Thread(ts);

            ts.BeginInvoke(null, null);
        }
        private void DeleteConfirmResponseHandler(MsgBxResultMessage obj)
        {
            if (obj.Result == eMessageBoxResult.Yes)
            {
                string jsonObj     = JsonConvert.SerializeObject(SelectedRole);
                var    httpContent = new StringContent(jsonObj, Encoding.UTF8, "application/json");
                var    response    = HttpManager.Instance.Post(httpContent, APIPaths.RoleDelete);
                ActionResult <string> actionResult = JsonConvert.DeserializeObject <ActionResult <string> >(response);

                switch (actionResult.ReturnCode)
                {
                case eReturnCode.Success:
                    ShowMessageBox(eMessageBoxType.Info, Application.Current.MainWindow.Resources["txtMsgTitleSuccess"].ToString(),
                                   Application.Current.MainWindow.Resources["txtMsgTextRoleDelSuccess"].ToString());
                    break;

                case eReturnCode.Failure:
                    ShowMessageBox(eMessageBoxType.Error, Application.Current.MainWindow.Resources["txtMsgTitleError"].ToString(),
                                   Application.Current.MainWindow.Resources["txtMsgTextRoleDelError"].ToString());
                    break;

                case eReturnCode.EmployeeExists:
                    ShowMessageBox(eMessageBoxType.Error, Application.Current.MainWindow.Resources["txtMsgTitleError"].ToString(),
                                   Application.Current.MainWindow.Resources["txtMsgTextRoleDelErrorEmployeeExists"].ToString());
                    break;

                case eReturnCode.SubOrdinateExists:
                    ShowMessageBox(eMessageBoxType.Error, Application.Current.MainWindow.Resources["txtMsgTitleError"].ToString(),
                                   Application.Current.MainWindow.Resources["txtMsgTextRoleDelErrorSubOrdinatesExists"].ToString());
                    break;
                }
                //else
                //{
                //    ShowMessageBox(eMessageBoxType.Error, Application.Current.MainWindow.Resources["txtMsgTitleError"].ToString(),
                //        Application.Current.MainWindow.Resources["txtMsgTextRoleDelError"].ToString());
                //}
                FetchData();
            }


            SelectedRole            = new OrgRoleDTO();
            SelectedRole.ParentRole = AllRoles.Where(r => r.ParentRoleId == 0).FirstOrDefault().Clone() as OrgRoleDTO;
            RaisePropertyChanged("SelectedRole");

            Messenger.Default.Unregister <MsgBxResultMessage>(this, DeleteConfirmResponseHandler);
        }
        private static void SelectionChangedCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            RoleSelector ms = sender as RoleSelector;

            if (ms.IsHandlingSelectionChangedCmd)
            {
                return;
            }
            ms.ExecuteSelctionChangedCallBack = false;
            ms.IsHandlingSelectionChangedCmd  = true;
            ObservableCollection <MultiSelectItem <OrgRoleDTO> > tempSelecItems = ms.GetValue(SelectionListProperty) as ObservableCollection <MultiSelectItem <OrgRoleDTO> >;
            OrgRoleDTO cmdParam         = e.Parameter as OrgRoleDTO;
            var        removedItem      = tempSelecItems.ToList().Where(item => item.Items.Contains(cmdParam)).First();
            int        removedItemIndex = tempSelecItems.IndexOf(removedItem);

            for (int i = removedItemIndex + 1; i < tempSelecItems.Count;)
            {
                tempSelecItems.RemoveAt(i);
            }

            if (cmdParam.ChildRoles.Count == 0)
            {
                if (tempSelecItems.Last().IsButton)
                {
                    tempSelecItems.RemoveAt(tempSelecItems.Count - 1);
                }
            }
            else
            {
                if (!tempSelecItems.Last().IsButton)
                {
                    tempSelecItems.Add(new MultiSelectItem <OrgRoleDTO>()
                    {
                        IsButton = true
                    });
                }
            }
            ms.SetValue(SelectionProperty, cmdParam);
            ms.SetValue(SelectionListProperty, tempSelecItems);

            ms.ExecuteSelctionChangedCallBack = true;
            ms.IsHandlingSelectionChangedCmd  = false;
            //Selection
        }
 private void CancelCommandHandler()
 {
     AppLogger.Instance.LogBegin(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     try
     {
         _isEdit                 = false;
         SelectedRole            = new OrgRoleDTO();
         SelectedRole.ParentRole = AllRoles.Where(r => r.ParentRoleId == 0).FirstOrDefault().Clone() as OrgRoleDTO;
         RaisePropertyChanged("SelectedRole");
         PageTitle = Application.Current.MainWindow.Resources["txtAddRole"].ToString();
         RaisePropertyChanged("PageTitle");
     }
     catch (Exception ex)
     {
         AppLogger.Instance.Log(eLogType.Error, ex.ToString());
     }
     finally
     {
         AppLogger.Instance.LogEnd(this.GetType().Name, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     }
 }
        private static void SelectionChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RoleSelector ms = d as RoleSelector;

            if (!ms.ExecuteSelctionChangedCallBack)
            {
                var x = ms.GetValue(SelectionProperty);
                ms.ExecuteSelctionChangedCallBack = true;
                return;
            }

            OrgRoleDTO newRole = e.NewValue as OrgRoleDTO;
            ObservableCollection <OrgRoleDTO> sourceItems = ms.GetValue(SourceProperty) as ObservableCollection <OrgRoleDTO>;

            if (sourceItems == null)
            {
                return;
            }
            ObservableCollection <MultiSelectItem <OrgRoleDTO> > tempSelctionList = ms.GetValue(SelectionListProperty) as ObservableCollection <MultiSelectItem <OrgRoleDTO> >;

            if (tempSelctionList != null)
            {
                tempSelctionList.Clear();
            }



            if (newRole == null || newRole.Id == 0)
            {
                AddInitial(sourceItems, ms);
                return;
            }

            OrgRoleDTO currentParentValue = e.NewValue as OrgRoleDTO;
            //Clearing current selection list
            ObservableCollection <MultiSelectItem <OrgRoleDTO> > tempSelectnList = ms.GetValue(SelectionListProperty) as ObservableCollection <MultiSelectItem <OrgRoleDTO> >;

            if (tempSelectnList != null)
            {
                tempSelectnList.Clear();
            }
            //Fetching Orginal list

            currentParentValue = (from role in sourceItems where role.Id == currentParentValue.Id select role).FirstOrDefault();
            ObservableCollection <MultiSelectItem <OrgRoleDTO> > tempSelecItems = new  ObservableCollection <MultiSelectItem <OrgRoleDTO> >();

            while (currentParentValue != null)
            {
                List <OrgRoleDTO> currentParentSiblings = (from role in sourceItems where role.ParentRoleId == currentParentValue.ParentRoleId select role).ToList();
                tempSelecItems.Add(new MultiSelectItem <OrgRoleDTO>()
                {
                    CurrentItem = currentParentValue, IsButton = false, Items = new ObservableCollection <OrgRoleDTO>(currentParentSiblings)
                });
                currentParentValue = (from role in sourceItems where role.Id == currentParentValue.ParentRoleId select role).FirstOrDefault();
            }
            tempSelecItems = new ObservableCollection <MultiSelectItem <OrgRoleDTO> > (tempSelecItems.Reverse());
            if (tempSelecItems.Last().CurrentItem.ChildRoles.Count > 0)
            {
                tempSelecItems.Add(new MultiSelectItem <OrgRoleDTO>()
                {
                    IsButton = true
                });
            }

            ms.SetValue(SelectionListProperty, tempSelecItems);
        }