Ejemplo n.º 1
0
 public FormDeleteDep(IController controller, List <string> deps, DepartmentCommand command, Action del) : this()
 {
     DepNameList = deps;
     Controller  = controller;
     isDel       = del;
     Command     = command;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Удаление отдела
        /// </summary>
        /// <param name="command"></param>
        public void Delete(DepartmentCommand command)
        {
            try
            {
                if (command.ParentDepartmentName == null)
                {
                    manager.DeleteDepartmentsAndChildrens(command.Id);
                }
                else
                {
                    Dictionary <string, string> pars = GetParam(command);
                    manager.DeleteDepartmentsAndMoveChildrens(command.Id, pars["ParentDepartmentID"]);
                }

                departmentEventsArgs.Message = "Удалено.";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                departmentEventsArgs.Message = String.Format("Ошибка. {0}", e.Message);
            }
            finally
            {
                modelDeptHandlerMessage.Invoke(this, departmentEventsArgs);
                UpdateTree();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Сохранение вновь созданного отдела
        /// </summary>
        /// <param name="command"></param>
        public void SaveNew(DepartmentCommand command)
        {
            try
            {
                bool result = manager.InsertDepartments(GetParam(command));
                departmentEventsArgs.Message = result ? "Новый отдел создан." : "Новый отдел не создан.";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                departmentEventsArgs.Message = String.Format("Ошибка. {0}", e.Message);
            }
            finally
            {
                modelDeptHandlerMessage.Invoke(this, departmentEventsArgs);

                IEnumerable <string> oldIds = Departments.Select(item => item.Id);
                UpdateTree();

                IEnumerable <string> newIds = Departments.Select(item => item.Id);
                List <string>        ids    = newIds.Except(oldIds).ToList();
                if (ids.Count > 0)
                {
                    departmentEventsArgs.Id = ids[0];
                    modelDeptHandlerId.Invoke(this, departmentEventsArgs);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Получение словаря с необходимыми полями для работы с БД
        /// </summary>
        /// <param name="command">Объект для преобразования</param>
        /// <returns>словарь</returns>
        private Dictionary <string, string> GetParam(DepartmentCommand command)
        {
            Dictionary <string, string> result = new Dictionary <string, string>()
            {
                { "Code", command.Code },
                { "Name", command.Name },
            };

            if (command.ParentDepartmentName != null)
            {
                Department dep = Departments.First(item => item.Name.Equals(command.ParentDepartmentName));
                result.Add("ParentDepartmentID", dep.Id);
            }
            return(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Сохранение параметров у отдела
 /// </summary>
 /// <param name="command"></param>
 public void SaveChange(DepartmentCommand command)
 {
     try
     {
         bool result = manager.UpdateDepartments(command.Id, GetParam(command));
         departmentEventsArgs.Message = result ? "Сохранено." : "Не сохранилось.";
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         departmentEventsArgs.Message = String.Format("Ошибка. {0}", e.Message);
     }
     finally
     {
         modelDeptHandlerMessage.Invoke(this, departmentEventsArgs);
         UpdateTree();
     }
 }
Ejemplo n.º 6
0
 public void Delete(DepartmentCommand command) => model.Delete(command);
Ejemplo n.º 7
0
 public void SaveNew(DepartmentCommand command) => model.SaveNew(command);
Ejemplo n.º 8
0
 public void SaveChange(DepartmentCommand command) => model.SaveChange(command);
        public async Task <CommandResult <DepartmentModel[]> > Handle(DepartmentCommand request, CancellationToken cancellationToken)
        {
            var lst = await organizationRepo.GetDepartments(request.SearchName).ConfigureAwait(false);

            return(await Task.FromResult <CommandResult <DepartmentModel[]> >(new CommandResult <DepartmentModel[]>() { Message = "Created successfully", Status = true, ResponseObj = lst }).ConfigureAwait(false));
        }