private void SaveButton_Click(object sender, EventArgs e) { // stop the flow of events this.rolesBindingSource.RaiseListChangedEvents = false; // commit edits in memory and unbind UnbindBindingSource(this.rolesBindingSource, true, true); try { _roles = _roles.Save(); this.Close(); } catch (Csla.DataPortalException ex) { MessageBox.Show(ex.BusinessException.ToString(), "Error saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { this.rolesBindingSource.DataSource = _roles; this.rolesBindingSource.RaiseListChangedEvents = true; this.rolesBindingSource.ResetBindings(false); } }
private void SaveRoleEdit() { var list = RoleEditList.GetRoles(); var item = list.GetRoleById(RoleEdit.Id); if (item == null) { list.Add(RoleEdit); } else { item.Name = RoleEdit.Name; } list.Save(); }
protected override void Execute(Csla.Rules.IRuleContext context) { var target = (RoleEdit)context.Target; RoleEditList parent = (RoleEditList)target.Parent; if (parent != null) { foreach (RoleEdit item in parent) { if (item.Id == target.ReadProperty(IdProperty) && !(ReferenceEquals(item, target))) { context.AddErrorResult("Role Id must be unique"); break; } } } }
public void DeleteRole() { var obj = RoleEditList.GetRoles(); var item = obj.AddNew(); Assert.IsTrue(item.IsNew); item.Name = "Unit Test Item"; obj = obj.Save(); item = (from r in obj where r.Name == "Unit Test Item" select r).First(); var id = item.Id; obj.Remove(item); obj = obj.Save(); Assert.AreEqual(0, obj.Where(r => r.Id == id).Count()); }
private void RolesEdit_Load(object sender, EventArgs e) { try { _roles = RoleEditList.GetRoles(); } catch (Csla.DataPortalException ex) { MessageBox.Show(ex.BusinessException.ToString(), "Data load error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Data load error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (_roles != null) this.rolesBindingSource.DataSource = _roles; }
public void AddRole() { var obj = RoleEditList.GetRoles(); var item = obj.AddNew(); Assert.IsTrue(item.IsNew); item.Name = "Test"; obj = obj.Save(); item = (from r in obj where r.Name == "Test" select r).First(); Assert.IsTrue(item.Id > 0); Assert.IsFalse(item.IsNew); Assert.IsFalse(item.IsDirty); obj.Remove(item); obj = obj.Save(); }
private void RolesEdit_Load(object sender, EventArgs e) { try { _roles = RoleEditList.GetRoles(); } catch (Csla.DataPortalException ex) { MessageBox.Show(ex.BusinessException.ToString(), "Data load error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Data load error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (_roles != null) { this.rolesBindingSource.DataSource = _roles; } }
public ActionResult EditList() { ViewData.Model = RoleEditList.GetRoles(); return(View()); }
public void GetList() { var obj = RoleEditList.GetRoles(); Assert.IsTrue(obj.Count > 0); }