public IHttpActionResult Update(int id) { try { var request = Context.GetCurrentRequest(); var siteId = request.GetQueryInt("siteId"); if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, ApplicationUtils.PluginId)) { return(Unauthorized()); } var departmentInfo = DepartmentManager.GetDepartmentInfo(siteId, id); departmentInfo.DepartmentName = request.GetPostString("departmentName"); departmentInfo.UserNames = request.GetPostString("userNames").Trim(','); departmentInfo.Taxis = request.GetPostInt("taxis"); DepartmentDao.Update(departmentInfo); return(Ok(new { Value = departmentInfo })); } catch (Exception ex) { return(InternalServerError(ex)); } }
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(); }
public void Save(Department model) { if (model == null) { throw new ArgumentException("department.Name is null"); } if (model.ID > 0) { dao.Update(model); } else { dao.Add(model); } Core.AccountManager.RefreshCache(); }
public ActionResult Edit(Department department) { if (ModelState.IsValid) { var dao = new DepartmentDao(); long id = dao.Update(department); if (id > 0) { SetAlert("Sửa thông tin nhân viên thành công", "success"); return(RedirectToAction("Index", "Department")); } else { SetAlert("Tài khoản hoặc mã nhân viên đã tồn tại!", "error"); return(RedirectToAction("Index", "Department")); } } SetAlert("Sửa thông tin nhân viên thất bại", "error"); return(RedirectToAction("Index", "Department")); }
/// <summary> /// 更新部门信息 /// </summary> /// <param name="dp"></param> /// <returns></returns> public bool Update(Department dp) { return(ddao.Update(dp)); }