示例#1
0
 public void GivenTheUserEnteresValidDepartmentDetails_()
 {
     departmentEditModel = new DepartmentEditModel
     {
         DepartmentName = PrimeActs.Service.IDGenerator.NewGuid('L').ToString().Replace("-", ""),
         //SelectedDivision = ""
     };
 }
示例#2
0
        public DepartmentEditModel UpdateDepartment(DepartmentEditModel model)
        {
            var department = ApplyChanges(model);

            department.ObjectState = ObjectState.Modified;

            department.UpdatedDate = DateTime.Now;
            _departmentService.Update(department);
            _departmentService.RefreshCache();
            return(model);
        }
        public async Task <IActionResult> Put([FromBody] DepartmentEditModel model)
        {
            var mapping = new Func <Department, Task <Department> >(async(entity) =>
            {
                entity.Name        = model.Name;
                entity.ParentId    = model.ParentId;
                entity.Description = model.Description;
                return(await Task.FromResult(entity));
            });

            return(await _PutRequest(model.Id, mapping));
        }
        public JsonResult Edit(DepartmentEditModel model)
        {
            var objectId = ObjectId.GenerateNewId();

            if (!string.IsNullOrEmpty(model.ID) && !ObjectId.TryParse(model.ID, out objectId))
            {
                return(Json(new
                {
                    Code = 300,
                    Msg = "ID is not allowed."
                }));
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                return(Json(new
                {
                    Code = 300,
                    Msg = "Name is not allowed to be empty."
                }));
            }

            if (model.ParentID == null)
            {
                model.ParentID = "";
            }

            if (model.AdministratorID == null)
            {
                model.AdministratorID = "";
            }

            var mongo = new MongoHelper();

            var filter = Builders <BsonDocument> .Filter.Eq("ID", objectId);

            var update1 = Builders <BsonDocument> .Update.Set("ParentID", model.ParentID);

            var update2 = Builders <BsonDocument> .Update.Set("Name", model.Name);

            var update3 = Builders <BsonDocument> .Update.Set("AdministratorID", model.AdministratorID);

            var update = Builders <BsonDocument> .Update.Combine(update1, update2, update3);

            mongo.UpdateOne(Constant.DepartmentCollectionName, filter, update);

            return(Json(new
            {
                Code = 200,
                Msg = "Saved successfully!"
            }));
        }
示例#5
0
        private Department ApplyChanges(DepartmentEditModel model)
        {
            return(new Department
            {
                DepartmentID = Guid.Empty != model.DepartmentId ? model.DepartmentId : PrimeActs.Service.IDGenerator.NewGuid(_serverCode.ToCharArray()[0]),
                DepartmentName = model.DepartmentName,
                IsActive = model.IsActive,

                UpdatedDate = string.IsNullOrWhiteSpace(model.UpdatedDate)? (DateTime?)null: DateTime.Parse(model.UpdatedDate),

                CreatedDate = string.IsNullOrWhiteSpace(model.CreatedDate) ? (DateTime?)null : DateTime.Parse(model.CreatedDate),
                DivisionID = model.RelatedDivisionId,
            });
        }
示例#6
0
        public DepartmentEditModel CreateDepartment(DepartmentEditModel model)
        {
            var department = ApplyChanges(model);

            department.ObjectState = ObjectState.Added;

            department.CreatedDate = DateTime.Now;
            department.IsActive    = true;
            _departmentService.Insert(department);

            _departmentService.RefreshCache();
            model.DepartmentId = department.DepartmentID;
            return(model);
        }
示例#7
0
 public void Delete(DepartmentEditModel obj)
 {
     Channel.Delete(obj);
     try
     {
         if (this.State != System.ServiceModel.CommunicationState.Faulted)
         {
             this.Close();
         }
     }
     catch (Exception)
     {
         this.Abort();
     }
 }
示例#8
0
        public DepartmentEditModel Insert(DepartmentEditModel obj)
        {
            var result = Channel.Insert(obj);

            try
            {
                if (this.State != System.ServiceModel.CommunicationState.Faulted)
                {
                    this.Close();
                }
            }
            catch (Exception)
            {
                this.Abort();
            }
            return(result);
        }
        public JsonResult Add(DepartmentEditModel model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                return(Json(new
                {
                    Code = 300,
                    Msg = "Name is not allowed to be empty."
                }));
            }

            if (model.ParentID == null)
            {
                model.ParentID = "";
            }

            if (model.AdministratorID == null)
            {
                model.AdministratorID = "";
            }

            var mongo = new MongoHelper();

            var doc = new BsonDocument
            {
                ["ID"]              = ObjectId.GenerateNewId(),
                ["ParentID"]        = model.ParentID,
                ["Name"]            = model.Name,
                ["AdministratorID"] = model.AdministratorID,
                ["Status"]          = 0
            };

            mongo.InsertOne(Constant.DepartmentCollectionName, doc);

            return(Json(new
            {
                Code = 200,
                Msg = "Saved successfully!"
            }));
        }
示例#10
0
 public void GivenTheUserHasnTEnteredDepartmentName()
 {
     departmentEditModel = new DepartmentEditModel {
         DepartmentName = ""
     };
 }
        public UserContextModel GetUserContext(IEnumerable <ApplicationUserRole> applicationUserRoles)
        {
            UserContextModel contextOptions = new UserContextModel();

            foreach (var applicationUserRole in applicationUserRoles)
            {
                CompanyModel        company    = null;
                DivisionModel       division   = null;
                DepartmentEditModel department = null;

                if (applicationUserRole.Company == null)
                {
                    // if company is null => access to all companies divisions and departments

                    foreach (var domainCompany in _companyService.GetAllCompanies())
                    {
                        company = new CompanyModel()
                        {
                            CompanyName = domainCompany.CompanyName,
                            CompanyId   = domainCompany.CompanyID
                        };

                        if (contextOptions.Companies.All(c => c.CompanyId != company.CompanyId))
                        {
                            contextOptions.Companies.Add(company);
                        }
                        else
                        {
                            company = contextOptions.Companies.Find(c => c.CompanyId == company.CompanyId);
                        }

                        foreach (var domainDivision in _divisonService.GetDivisionsByCompanyID(domainCompany.CompanyID))
                        {
                            division = new DivisionModel()
                            {
                                DivisionName = domainDivision.DivisionName,
                                DivisionId   = domainDivision.DivisionID
                            };

                            if (company.Divisions.All(d => d.DivisionId != division.DivisionId))
                            {
                                company.Divisions.Add(division);
                            }
                            else
                            {
                                division = company.Divisions.Find(d => d.DivisionId == division.DivisionId);
                            }

                            division.Departments.AddRange(
                                _departmentService.GetAllDeptByDivID(domainDivision.DivisionID)
                                .Select(
                                    c =>
                                    new DepartmentEditModel()
                            {
                                DepartmentName = c.DepartmentName,
                                DepartmentId   = c.DepartmentID
                            }));
                        }
                    }

                    continue;
                }

                company = new CompanyModel()
                {
                    CompanyName = applicationUserRole.Company.CompanyName,
                    CompanyId   = applicationUserRole.CompanyId ?? Guid.Empty
                };

                if (contextOptions.Companies.All(c => c.CompanyId != company.CompanyId))
                {
                    contextOptions.Companies.Add(company);
                }
                else
                {
                    company = contextOptions.Companies.Find(c => c.CompanyId == company.CompanyId);
                }

                if (applicationUserRole.Division == null)
                {
                    // if division is null => access to all divisions and departments

                    foreach (
                        var domainDivision in _divisonService.GetDivisionsByCompanyID(applicationUserRole.Company.CompanyID))
                    {
                        division = new DivisionModel()
                        {
                            DivisionName = domainDivision.DivisionName,
                            DivisionId   = domainDivision.DivisionID
                        };

                        if (company.Divisions.All(d => d.DivisionId != division.DivisionId))
                        {
                            company.Divisions.Add(division);
                        }
                        else
                        {
                            division = company.Divisions.Find(d => d.DivisionId == division.DivisionId);
                        }

                        division.Departments.AddRange(
                            _departmentService.GetAllDeptByDivID(domainDivision.DivisionID)
                            .Select(
                                c =>
                                new DepartmentEditModel()
                        {
                            DepartmentName = c.DepartmentName,
                            DepartmentId   = c.DepartmentID
                        }));
                    }

                    continue;
                }

                division = new DivisionModel()
                {
                    DivisionName = applicationUserRole.Division.DivisionName,
                    DivisionId   = applicationUserRole.DivisionId ?? Guid.Empty
                };

                if (company.Divisions.All(d => d.DivisionId != division.DivisionId))
                {
                    company.Divisions.Add(division);
                }
                else
                {
                    division = company.Divisions.Find(d => d.DivisionId == division.DivisionId);
                }

                if (applicationUserRole.Department == null)
                {
                    division.Departments.AddRange(
                        applicationUserRole.Division.Departments.Select(
                            c => new DepartmentEditModel()
                    {
                        DepartmentName = c.DepartmentName, DepartmentId = c.DepartmentID
                    }));
                    continue;
                }

                department = new DepartmentEditModel()
                {
                    DepartmentName = applicationUserRole.Department.DepartmentName,
                    DepartmentId   = applicationUserRole.DepartmentId ?? Guid.Empty
                };
                division.Departments.Add(department);
            }

            return(contextOptions);
        }
 public void Delete(DepartmentEditModel obj)
 {
     _service.Delete(obj.Target);
 }
 public void Update(DepartmentEditModel obj)
 {
     _service.Update(obj.Target);
 }
        public DepartmentEditModel Insert(DepartmentEditModel obj)
        {
            var item = _service.Insert(obj.Target);

            return(BuildModel(item));
        }
示例#15
0
        private async void btnOK_Click(object sender, RoutedEventArgs e)
        {
            #region 新增
            if (Om == OperationMode.AddMode)
            {
                string strErrorMsg = string.Empty;
                try
                {
                    DepartmentEditModel newEditDepartment = new DepartmentEditModel();
                    newEditDepartment.DepartmentCode = txtDeptCode.Text.Trim();
                    newEditDepartment.Name           = txtName.Text.Trim();
                    newEditDepartment.ShowIndex      = Convert.ToInt16(txtShowIndex.Value.Value);
                    newEditDepartment.Remark         = txtRemark.Text.Trim();
                    newEditDepartment.IsRealy        = chkIsRealDept.IsChecked.HasValue ? chkIsRealDept.IsChecked.Value : false;

                    DepartmentDisplayModel selectDept = cmbFatherDept.SelectedItem as DepartmentDisplayModel;
                    if (selectDept != null)
                    {
                        newEditDepartment.ParentCode = selectDept.Code;
                    }

                    newEditDepartment = await asyncProxy.CallAsync(c => c.Add(newEditDepartment, IsParent));

                    this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "新增部门成功!");
                    //MessageDialogResult result = await DialogManager.ShowMessageAsync(this, UIResources.MsgInfo, "新增部门成功!", MessageDialogStyle.Affirmative, null);
                    this.DialogResult = true;

                    #region 延时1s的弹窗
                    ////this.MetroDialogOptions.ColorScheme = UseAccentForDialogsMenuItem.IsChecked ? MetroDialogColorScheme.Accented : MetroDialogColorScheme.Theme;
                    //this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "新增部门成功!");
                    #endregion
                }
                catch (TimeoutException timeProblem)
                {
                    strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
                }
                catch (FaultException <LCFault> af)
                {
                    strErrorMsg = af.Detail.Message;
                }
                catch (FaultException unknownFault)
                {
                    strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
                }
                catch (CommunicationException commProblem)
                {
                    strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
                }
                if (strErrorMsg != string.Empty)
                {
                    await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "新增部门失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);

                    //AisinoMessageBox.Show("新增部门失败!原因:" + strMsg, UIResources.MsgError, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
            }
            #endregion

            #region 修改
            else
            {
                SelectSysDepartment.Name      = txtName.Text.Trim();
                SelectSysDepartment.ShowIndex = Convert.ToInt16(txtShowIndex.Value.Value);
                SelectSysDepartment.Remark    = txtRemark.Text.Trim();
                SelectSysDepartment.IsRealy   = chkIsRealDept.IsChecked.HasValue ? chkIsRealDept.IsChecked.Value : false;
                SelectSysDepartment.Stopped   = chkIsStoped.IsChecked.HasValue ? chkIsStoped.IsChecked.Value : false;
                DepartmentDisplayModel selectDept = cmbFatherDept.SelectedItem as DepartmentDisplayModel;
                if (selectDept != null)
                {
                    SelectSysDepartment.ParentCode = selectDept.Code;
                }

                string strErrorMsg = string.Empty;

                try
                {
                    SelectSysDepartment = await asyncProxy.CallAsync(c => c.Update(SelectSysDepartment));

                    //MessageDialogResult result = await DialogManager.ShowMessageAsync(this, UIResources.MsgInfo, "修改部门成功!", MessageDialogStyle.Affirmative, null);
                    this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "修改部门成功!");
                    this.DialogResult = true;
                }
                catch (TimeoutException timeProblem)
                {
                    strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
                }
                catch (FaultException <LCFault> af)
                {
                    strErrorMsg = af.Detail.Message;
                }
                catch (FaultException unknownFault)
                {
                    strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
                }
                catch (CommunicationException commProblem)
                {
                    strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
                }
                if (strErrorMsg != string.Empty)
                {
                    await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "修改部门失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);

                    //AisinoMessageBox.Show("修改部门失败!原因:" + strMsg, UIResources.MsgError, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
            }
            #endregion
        }
示例#16
0
        private async void BindDepartment(DepartmentEditModel selectDepartment)
        {
            string strErrorMsg = string.Empty;

            try
            {
                lstDepartments = await asyncProxy.CallAsync(c => c.GetAllDisplayModel());

                if (lstDepartments != null && lstDepartments.Count > 0)
                {
                    cmbFatherDept.ItemsSource       = lstDepartments;
                    cmbFatherDept.DisplayMemberPath = "Name";
                    cmbFatherDept.SelectedIndex     = 0;
                }
                if (this.Om == OperationMode.EditMode)
                {
                    if (selectDepartment != null)
                    {
                        foreach (DepartmentDisplayModel deptItem in cmbFatherDept.Items)
                        {
                            if (deptItem.Code == selectDepartment.ParentCode)
                            {
                                cmbFatherDept.SelectedItem = deptItem;
                                break;
                            }
                        }

                        txtDeptCode.Text        = selectDepartment.DepartmentCode == null ? "" : selectDepartment.DepartmentCode.Trim();
                        txtName.Text            = selectDepartment.Name == null ? "" : selectDepartment.Name.Trim();
                        txtShowIndex.Value      = selectDepartment.ShowIndex;
                        txtRemark.Text          = selectDepartment.Remark == null ? "" : selectDepartment.Remark.Trim();
                        chkIsRealDept.IsChecked = selectDepartment.IsRealy;
                        chkIsStoped.IsChecked   = selectDepartment.Stopped;
                    }
                }
                else if (this.Om == OperationMode.AddMode)
                {
                    if (selectDepartment != null)
                    {
                        cmbFatherDept.Text = selectDepartment.Name;
                    }
                }
            }
            catch (TimeoutException timeProblem)
            {
                strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message;
            }
            catch (FaultException <LCFault> af)
            {
                strErrorMsg = af.Detail.Message;
            }
            catch (FaultException unknownFault)
            {
                strErrorMsg = UIResources.UnKnowFault + unknownFault.Message;
            }
            catch (CommunicationException commProblem)
            {
                strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace;
            }
            catch (Exception ex)
            {
                strErrorMsg = ex.Message;
                //AisinoMessageBox.Show(ex.Message, UIResources.MsgInfo, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
            }
            if (strErrorMsg != string.Empty)
            {
                await DialogManager.ShowMessageAsync(this, UIResources.MsgError, "绑定部门信息失败!原因:" + strErrorMsg, MessageDialogStyle.Affirmative, null);
            }
        }