Exemplo n.º 1
0
        /// <summary>
        /// 同步部门
        /// </summary>
        /// <param name="organizeListJson">机构列表Json</param>
        /// <returns></returns>
        public void Synchronization(string organizeListJson)
        {
            List <WeChatDeptRelationEntity> weChatDeptRelationList = new List <WeChatDeptRelationEntity>();
            List <OrganizeEntity>           organizelist           = organizeListJson.ToList <OrganizeEntity>();

            #region  除
            IEnumerable <WeChatDeptRelationEntity> DeletedList = this.GetDeletedList(organizelist);
            foreach (var item in DeletedList)
            {
                DepartmentDelete departmentDelete = new DepartmentDelete();
                departmentDelete.id = item.WeChatDeptId.ToString();
                int IsOk = departmentDelete.Send().errcode;
                if (IsOk == 0)
                {
                    service.RemoveForm(item.DeptRelationId);
                }
            }
            #endregion

            #region 添加、编辑
            foreach (OrganizeEntity departmentEntity in organizelist)
            {
                WeChatDeptRelationEntity weChatDeptRelationEntity = service.GetEntity(departmentEntity.OrganizeId);
                if (weChatDeptRelationEntity == null)
                {
                    #region 添加
                    DepartmentCreate departmentCreate = new DepartmentCreate();
                    departmentCreate.name     = departmentEntity.FullName;
                    departmentCreate.parentid = departmentEntity.ParentId == "0" ? "1" : weChatDeptRelationList.Find(t => t.DeptId == departmentEntity.ParentId).WeChatDeptId.ToString();
                    string WeChatDeptId = departmentCreate.Send().id;
                    if (WeChatDeptId != null)
                    {
                        weChatDeptRelationEntity = new WeChatDeptRelationEntity();
                        weChatDeptRelationEntity.DeptRelationId = departmentEntity.OrganizeId;
                        weChatDeptRelationEntity.DeptId         = departmentEntity.OrganizeId;
                        weChatDeptRelationEntity.DeptName       = departmentEntity.FullName;
                        weChatDeptRelationEntity.WeChatDeptId   = WeChatDeptId.ToInt();//企业号创建部门的返回Id
                        weChatDeptRelationList.Add(weChatDeptRelationEntity);
                        service.SaveForm("", weChatDeptRelationEntity);
                    }
                    #endregion
                }
                else
                {
                    #region 编辑
                    weChatDeptRelationList.Add(weChatDeptRelationEntity);
                    DepartmentUpdate departmentUpdate = new DepartmentUpdate();
                    departmentUpdate.name     = departmentEntity.FullName;
                    departmentUpdate.parentid = departmentEntity.ParentId == "0" ? "1" : weChatDeptRelationList.Find(t => t.DeptId == departmentEntity.ParentId).WeChatDeptId.ToString();
                    departmentUpdate.id       = weChatDeptRelationEntity.WeChatDeptId.ToString();
                    int IsOk = departmentUpdate.Send().errcode;
                    if (IsOk == 0)
                    {
                        service.SaveForm(weChatDeptRelationEntity.DeptRelationId, weChatDeptRelationEntity);
                    }
                    #endregion
                }
            }
            #endregion
        }
 public IHttpActionResult Post(DepartmentCreate teacher)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (!_departmentService.CreateDepartment(teacher))
     {
         return(InternalServerError());
     }
     return(Ok("Department created."));
 }
Exemplo n.º 3
0
 public void CreateDepartmentApplication()
 {
     Pages.Business_Page.CheckDepartmentIsNull();
     Pages.Business_Page.EnterDepaertmentWindow();
     DepartmentCreate.ClickOn();
     DepartmentConfirm.ClickOn();
     softAssert.VerifyElementPresentInsideWindow(DepNameValidationPopup, DepartmentCloseButton);
     DepartmentName.EnterClearText(Constant.departmentName + RandomNumber.smallNumber());
     DepartmentConfirm.ClickOn();
     softAssert.VerifyElementPresentInsideWindow(DepartmentDelete, DepartmentCloseButton);
     softAssert.VerifyElementHasEqual(utility.TableCount(departmentTableCount), Constant.tmpTableCount + 1);
 }
        // Create Department
        public static DepartmentCreate.Response Handle(IRepository repository, DepartmentCreate.Request request)
        {
            // Validation now performed in the dispacther decorators (See AutoValidate<T> in the DomainBootstrapper class)

            var container = DepartmentFactory.Create(request.CommandModel);
            var validationDetails = repository.Save(container);

            var deptId = default(int?);
            if (!validationDetails.HasValidationIssues)
                deptId = container.FindEntity<Department>().DepartmentID;

            return new DepartmentCreate.Response(validationDetails, deptId);
        }
        public bool CreateDepartment(DepartmentCreate model)
        {
            var entity = new Department()
            {
                DepartmentName = model.DepartmentName,
                EmployeeCount  = model.EmployeeCount
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.DepartmentDbSet.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public async Task<ActionResult> Create(DepartmentCreate.CommandModel commandModel)
        {
            var request = new DepartmentCreate.Request(SystemPrincipal.Name, commandModel);
            var response = await DomainServices.DispatchAsync<DepartmentCreate.Response>(request);

            if (!response.HasValidationIssues)
                return RedirectToAction("Index");

            var instructors = await _QueryRepository.GetEntitiesAsync<Instructor>(new AsNoTrackingQueryStrategy()); ;
            ViewBag.InstructorID = new SelectList(instructors, "ID", "FullName", commandModel.InstructorID);

            ModelState.AddRange(response.ValidationDetails);
            return View(commandModel);
        }
Exemplo n.º 7
0
        public IHttpActionResult Post(DepartmentCreate department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateDepartmentService();

            if (!service.CreateDepartment(department))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
        public bool CreateDepartment(DepartmentCreate model)
        {
            var entity =
                new Department()
            {
                Name     = model.Name,
                Building = model.Building
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Departments.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public bool CreateDepartment(DepartmentCreate model)
        {
            var entity =
                new Department()
            {
                DeptName   = model.DeptName,
                BuildingId = model.BuildingId,
                Location   = model.Location,
                Room       = model.Room
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Departments.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Create(DepartmentCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            var service = CreateDepartmentService();

            if (service.CreateDepartment(model))
            {
                TempData["SaveResult"] = "Your Department was created.";
                return(RedirectToAction("Index"));
            }
            ;

            return(View(model));
        }
Exemplo n.º 11
0
        public void GetXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <create>
        <DEPARTMENT>
            <DEPARTMENTID>D1234</DEPARTMENTID>
            <TITLE>hello world</TITLE>
        </DEPARTMENT>
    </create>
</function>";

            DepartmentCreate record = new DepartmentCreate("unittest")
            {
                DepartmentId   = "D1234",
                DepartmentName = "hello world"
            };

            this.CompareXml(expected, record);
        }
        public void GetXmlTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <create>
        <DEPARTMENT>
            <DEPARTMENTID>D1234</DEPARTMENTID>
            <TITLE>hello world</TITLE>
        </DEPARTMENT>
    </create>
</function>";

            Stream            stream      = new MemoryStream();
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Encoding    = Encoding.UTF8;
            xmlSettings.Indent      = true;
            xmlSettings.IndentChars = "    ";

            IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings);

            DepartmentCreate record = new DepartmentCreate("unittest");

            record.DepartmentId   = "D1234";
            record.DepartmentName = "hello world";

            record.WriteXml(ref xml);

            xml.Flush();
            stream.Position = 0;
            StreamReader reader = new StreamReader(stream);

            Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd())
                           .WithDifferenceEvaluator(DifferenceEvaluators.Default)
                           .Build();

            Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString());
        }