public IHttpActionResult Insert()
        {
            try
            {
                var request = Context.GetCurrentRequest();
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, ApplicationUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var departmentInfo = new DepartmentInfo
                {
                    Id             = 0,
                    SiteId         = siteId,
                    DepartmentName = request.GetPostString("departmentName"),
                    UserNames      = request.GetPostString("userNames").Trim(','),
                    Taxis          = request.GetPostInt("taxis")
                };

                departmentInfo.Id = DepartmentDao.Insert(departmentInfo);

                return(Ok(new
                {
                    Value = departmentInfo
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Esempio n. 2
0
        public void IntegrationTest()
        {
            var connection = TestSession.GetConnection();

            connection.Open();
            #region good insertion and select by id test
            DepartmentModel inserted = new DepartmentModel();
            inserted.Name         = TestSession.Random.RandomString(50);
            inserted.GroupName    = TestSession.Random.RandomString(50);
            inserted.ModifiedDate = TestSession.Random.RandomDateTime();

            _tested.Insert(connection, new[] { inserted });

            var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new DepartmentModelPrimaryKey()
            {
                DepartmentID = inserted.DepartmentID,
            });

            CollectionAssert.IsNotEmpty(selectedAfterInsertion);
            var selectedAfterInsert = selectedAfterInsertion.Single();
            Assert.AreEqual(inserted.DepartmentID, selectedAfterInsert.DepartmentID);
            Assert.AreEqual(inserted.Name, selectedAfterInsert.Name);
            Assert.AreEqual(inserted.GroupName, selectedAfterInsert.GroupName);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate);

            #endregion

            #region update and select by id test
            inserted.Name         = TestSession.Random.RandomString(50);
            inserted.GroupName    = TestSession.Random.RandomString(50);
            inserted.ModifiedDate = TestSession.Random.RandomDateTime();

            _tested.Update(connection, new[] { inserted });

            var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new DepartmentModelPrimaryKey()
            {
                DepartmentID = inserted.DepartmentID,
            });

            CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss);
            var selectedAfterUpdate = selectedAfterUpdateAddresss.Single();
            Assert.AreEqual(inserted.DepartmentID, selectedAfterUpdate.DepartmentID);
            Assert.AreEqual(inserted.Name, selectedAfterUpdate.Name);
            Assert.AreEqual(inserted.GroupName, selectedAfterUpdate.GroupName);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate);

            #endregion

            #region delete test
            _tested.Delete(connection, new[] { inserted });
            var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new DepartmentModelPrimaryKey()
            {
                DepartmentID = inserted.DepartmentID,
            });
            CollectionAssert.IsEmpty(selectedAfterDeleteAddresss);
            #endregion
            connection.Close();
        }
        private List <DepartmentDto> GetDepartmentList()
        {
            List <DepartmentDto> departmentList = new DepartmentDao().GetAllDepartment();
            DepartmentDto        allDepartment  = new DepartmentDto();

            allDepartment.Code = 0;
            allDepartment.Name = "全部署";
            departmentList.Insert(0, allDepartment);
            return(departmentList);
        }
Esempio n. 4
0
        public ActionResult Create(Department department)
        {
            if (ModelState.IsValid)
            {
                var dao = new DepartmentDao();

                long id = dao.Insert(department);
                if (id > 0)
                {
                    SetAlert("Thêm chấm công nhân viên thành công", "success");
                    return(RedirectToAction("Index", "Department"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm chấm nhân viên công không thành công");
                }
            }
            SetAlert("Error", "error");
            return(RedirectToAction("Index", "Department"));
        }