Inheritance: INotifyPropertyChanging, INotifyPropertyChanged
Beispiel #1
0
        public virtual ActionResult Edit(Models.Role role)
        {
            Models.Role originalItem =
                DatabaseContext.Roles.Find(role.Id);

            if (originalItem == null)
            {
                return(HttpNotFound());
            }

            var foundedItem =
                DatabaseContext.Roles
                .Where(current => current.Id != role.Id)
                .Where(current => string.Compare
                           (current.Name, role.Name, true) == 0)
                .FirstOrDefault();

            if (foundedItem != null)
            {
                ModelState.AddModelError(key: "Name", errorMessage: "This Is Exist, Choose Another One!");
            }

            if (ModelState.IsValid)
            {
                originalItem.Name     = role.Name;
                originalItem.IsActive = role.IsActive;

                DatabaseContext.SaveChanges();

                return(RedirectToAction(MVC.Roles.Index()));
            }

            return(View(model: role));
        }
        public virtual void RemoveRole(Role role)
        {
            if (!Roles.Contains(role)) return;

            role.Person = null;

            Roles.Remove(role);
        }
        public virtual void AddRole(Role role)
        {
            if (Roles.Contains(role)) return;

            role.Person = this;

            Roles.Add(role);
        }
Beispiel #4
0
        public virtual ActionResult Create()
        {
            Models.Role DefaultRole = new Models.Role();

            DefaultRole.IsActive = true;

            return(View(model: DefaultRole));
        }
Beispiel #5
0
        public virtual ActionResult Create([Bind(Exclude = "Id")] Models.Role role)
        {
            var FoundedItem =
                DatabaseContext.Roles
                .Where(current => string.Compare
                           (current.Name, role.Name, true) == 0)
                .FirstOrDefault();

            if (FoundedItem != null)
            {
                ModelState.AddModelError(key: "Name", errorMessage: "This Is Exist, Choose Another One!");
            }

            if (ModelState.IsValid)
            {
                DatabaseContext.Roles.Add(role);
                DatabaseContext.SaveChanges();
                return(RedirectToAction(MVC.Roles.Index()));
            }

            return(View(model: role));
        }
 public static bool IsInRole(this User user, Role role)
 {
     return user != null && user.Role == role;
 }
 partial void DeleteRole(Role instance);
 partial void UpdateRole(Role instance);
 partial void InsertRole(Role instance);