Пример #1
0
 public ActionResult Delete(int id, RoleEdit role)
 {
     try
     {
         var list = RoleEditList.GetRoles();
         var item = list.GetRoleById(id);
         list.Remove(item);
         list.Save();
         return(RedirectToAction("Index"));
     }
     catch (Csla.DataPortalException ex)
     {
         if (ex.BusinessException != null)
         {
             ModelState.AddModelError("", ex.BusinessException.Message);
         }
         else
         {
             ModelState.AddModelError("", ex.Message);
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     // failure condition
     LoadProperty(role, RoleEdit.IdProperty, id);
     ViewData.Model = role;
     return(View());
 }
Пример #2
0
        public void UpdateRole()
        {
            var obj = RoleEditList.GetRoles();

            var item = obj.AddNew();

            Assert.IsTrue(item.IsNew);
            item.Name = "Unit Test Item";
            obj       = obj.Save();
            obj       = RoleEditList.GetRoles();

            item = (from r in obj
                    where r.Name == "Unit Test Item"
                    select r).First();
            item.Name = "Unit Test Item Update";
            var id = item.Id;

            Assert.IsTrue(item.IsDirty);
            obj = obj.Save();

            item = (from r in obj
                    where r.Id == id
                    select r).First();
            Assert.AreEqual("Unit Test Item Update", item.Name);
            Assert.IsFalse(item.IsNew);
            Assert.IsFalse(item.IsDirty);

            obj.Remove(item);
            obj = obj.Save();
        }
Пример #3
0
        public ActionResult EditList(FormCollection collection)
        {
            var list = RoleEditList.GetRoles();

            UpdateModel(list, collection);
            SaveObject(list, false);
            return(View());
        }
Пример #4
0
        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();
        }
Пример #5
0
        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());
        }
Пример #6
0
        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();
        }
Пример #7
0
 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;
     }
 }
Пример #8
0
 public ActionResult EditList()
 {
     ViewData.Model = RoleEditList.GetRoles();
     return(View());
 }
Пример #9
0
        public void GetList()
        {
            var obj = RoleEditList.GetRoles();

            Assert.IsTrue(obj.Count > 0);
        }