/// <summary> /// Handle form submit, delete all from table and re-insert /// </summary> /// <param name="zoneList"></param> /// <returns></returns> protected string handleZoneAuthorityUpdate(List <CmsPageSecurityZone> zoneList, List <WebPortalUserRole> roleList) { if (PageUtils.getFromForm("update", "") != "updateZoneAuthority") { return(""); } List <CmsPageSecurityZoneUserRole> authority = new List <CmsPageSecurityZoneUserRole>(); foreach (CmsPageSecurityZone z in zoneList) { roleDb.deleteByZone(z); foreach (WebPortalUserRole r in roleList) { // for each zone and role, we expect a pair of html input elements: R, W string htmlInputName = "z" + z.Id + "r" + r.RoleID; string[] accessMode = PageUtils.getFromForm(htmlInputName); if (accessMode.Length == 0) { continue; } CmsPageSecurityZoneUserRole entity = createUserRoleEntity(z, r, accessMode); authority.Add(entity); } } if (roleDb.insert(authority)) { return(formatNormalMsg("Updated successfully.")); } else { return(formatErrorMsg("Database error, please contract administrator.")); } }
public void CanDeleteByZone() { CmsPageSecurityZoneUserRoleDb dboperation = new CmsPageSecurityZoneUserRoleDb(); CmsPageSecurityZone z = new CmsPageSecurityZone(2); //z.Id = 2; dboperation.deleteByZone(z); Assert.That(dboperation.fetchAllByZone(z).Count, Is.EqualTo(0)); }