コード例 #1
0
        public IHttpActionResult PostAccRole(AccRole accRole)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AccRoles.Add(accRole);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (AccRoleExists(accRole.AccRoleID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = accRole.AccRoleID }, accRole));
        }
コード例 #2
0
        public IHttpActionResult PutAccRole(int id, AccRole accRole)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != accRole.AccRoleID)
            {
                return(BadRequest());
            }

            db.Entry(accRole).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccRoleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public IHttpActionResult GetAccRole(int id)
        {
            AccRole accRole = db.AccRoles.Find(id);

            if (accRole == null)
            {
                return(NotFound());
            }

            return(Ok(accRole));
        }
コード例 #4
0
        public IHttpActionResult DeleteAccRole(int id)
        {
            AccRole accRole = db.AccRoles.Find(id);

            if (accRole == null)
            {
                return(NotFound());
            }

            db.AccRoles.Remove(accRole);
            db.SaveChanges();

            return(Ok(accRole));
        }
        public async Task <bool> UpdateAsync(AccRole role)
        {
            if (role.Name.Length < 1)
            {
                throw new BadRequestException("Role name must be longer than 1 character.");
            }

            var exists = await roleManager.RoleExistsAsync(role.Name);

            if (!exists)
            {
                throw new NotFoundException();
            }

            var result = await roleManager.UpdateAsync(role);

            return(result.Succeeded);
        }
        public async Task <AccRole> AddAsync(AccRole role)
        {
            if (role.Name.Length < 1)
            {
                throw new BadRequestException("Role name must be longer than 1 character.");
            }

            var exists = await roleManager.RoleExistsAsync(role.Name);

            if (exists)
            {
                throw new ConflictException("Role already exists.");
            }

            await roleManager.CreateAsync(role);

            var newRole = await roleManager.FindByIdAsync(role.Id.ToString());

            return(newRole);
        }
コード例 #7
0
ファイル: MsaaHelper.cs プロジェクト: Gnail-nehc/Black
 public static IAccessible GetAccessibleObjectByNameAndRole(IAccessible iaccWindow, string accName, AccRole accRole)
 {
     IAccessible objReturn = default(IAccessible);
     int childCount = iaccWindow.accChildCount;
     object[] windowChildren = new object[childCount];
     int pcObtained;
     int result = AccessibleChildren(iaccWindow, 0, childCount, windowChildren, out pcObtained);
     string name = "";
     int role;
     for (int i = 0; i < windowChildren.Count(); i++)
     {
         if (windowChildren[i].GetType() != typeof(int) && windowChildren[i].GetType() != typeof(string))
         {
             IAccessible child = windowChildren[i] as IAccessible;
             role = (int)child.get_accRole(CHILDID_SELF);
             name = child.get_accName(CHILDID_SELF);
             if (accName.Equals(name, StringComparison.CurrentCultureIgnoreCase) && role == accRole.GetHashCode())
             {
                 return child;
             }
             objReturn = GetAccessibleObjectByNameAndRole(child, accName, accRole);
             if (objReturn != default(IAccessible))
             {
                 return objReturn;
             }
         }
     }
     return objReturn;
 }
        public static void Initialize(AccountServiceContext context)
        {
            context.Database.EnsureCreated();

            //Look for any students.
            //if (context.AccUsers.Any())
            //{
            //    //return;   // DB has been seeded
            //}

            context.Database.EnsureDeleted();
            context.Database.Migrate();

            #region AccRole
            var accRoles = new AccRole[]
            {
                new AccRole {
                    Id   = Guid.Parse("c8ae737c-ed9b-4fee-be6f-9c74ba376ae7"),
                    Name = "Administrator"
                },
                new AccRole {
                    Id   = Guid.Parse("56860de3-f338-449c-be26-c946d4cb73b0"),
                    Name = "User"
                },
                new AccRole {
                    Id   = Guid.Parse("5a1808ce-43b3-4e8b-9789-271b33b04f43"),
                    Name = "Corporation"
                }
            };
            foreach (AccRole ar in accRoles)
            {
                context.AccRoles.Add(ar);
            }
            context.SaveChanges();
            #endregion

            #region City
            var cities = new City[]
            {
                new City {
                    ID   = Guid.Parse("e5a60ae7-4c82-4678-8d98-6c711d9c7d3f"),
                    Name = "Novi Sad"
                },
                new City {
                    ID   = Guid.Parse("d09118cb-05b7-4d5a-864a-6fd5199b794a"),
                    Name = "Beograd"
                },
                new City {
                    ID   = Guid.Parse("397f7650-6ef5-4b52-ad73-e6d3df1f2816"),
                    Name = "Nis"
                }
            };
            foreach (City c in cities)
            {
                context.Cities.Add(c);
            }
            context.SaveChanges();
            #endregion

            #region Accounts
            var accounts = new Account[]
            {
                new Account {
                    Id            = Guid.Parse("259064f5-fdd5-4dbd-965e-79129c3bc0e3"),
                    FirstName     = "Petar",
                    LastName      = "Petrovic",
                    UserName      = "******",
                    Email         = "*****@*****.**",
                    StreetAddress = "Bulevar cara Lazara 7a",
                    CityId        = Guid.Parse("e5a60ae7-4c82-4678-8d98-6c711d9c7d3f"),
                    RoleId        = Guid.Parse("c8ae737c-ed9b-4fee-be6f-9c74ba376ae7") // Administrator
                },
                new Account {
                    Id            = Guid.Parse("d59101e6-feaa-421f-9392-793f86bdaf4b"),
                    FirstName     = "Marko",
                    LastName      = "Markovic",
                    UserName      = "******",
                    Email         = "*****@*****.**",
                    StreetAddress = "Žitni trg 4",
                    CityId        = Guid.Parse("e5a60ae7-4c82-4678-8d98-6c711d9c7d3f"),
                    RoleId        = Guid.Parse("56860de3-f338-449c-be26-c946d4cb73b0") // User
                },
                new Account {
                    Id            = Guid.Parse("1f11e055-0409-4467-b8d9-245049d69d7b"),
                    FirstName     = "Nikola",
                    LastName      = "Nikolic",
                    UserName      = "******",
                    Email         = "*****@*****.**",
                    StreetAddress = "Danila Kiša 13",
                    CityId        = Guid.Parse("d09118cb-05b7-4d5a-864a-6fd5199b794a"),
                    RoleId        = Guid.Parse("56860de3-f338-449c-be26-c946d4cb73b0") // User
                }
            };
            foreach (Account a in accounts)
            {
                context.Accounts.Add(a);
            }
            context.SaveChanges();
            #endregion
        }
コード例 #9
0
 public static IEnumerable <IAccessible> FindDescendantsByRole(this IAccessible element, AccRole role)
 {
     return(GetDescendants(element));
 }
コード例 #10
0
        public static bool IsRoleSafe(this IAccessible element, AccRole role)
        {
            var actualRole = element.GetRoleSafe();

            return(actualRole == default(AccRole) || actualRole == role);
        }
コード例 #11
0
        public static IAccessible GetAccessibleObjectByNameAndRole(IAccessible iaccWindow, string accName, AccRole accRole)
        {
            IAccessible objReturn  = default(IAccessible);
            int         childCount = iaccWindow.accChildCount;

            object[] windowChildren = new object[childCount];
            int      pcObtained;
            int      result = AccessibleChildren(iaccWindow, 0, childCount, windowChildren, out pcObtained);
            string   name   = "";
            int      role;

            for (int i = 0; i < windowChildren.Count(); i++)
            {
                if (windowChildren[i].GetType() != typeof(int) && windowChildren[i].GetType() != typeof(string))
                {
                    IAccessible child = windowChildren[i] as IAccessible;
                    role = (int)child.get_accRole(CHILDID_SELF);
                    name = child.get_accName(CHILDID_SELF);
                    if (accName.Equals(name, StringComparison.CurrentCultureIgnoreCase) && role == accRole.GetHashCode())
                    {
                        return(child);
                    }
                    objReturn = GetAccessibleObjectByNameAndRole(child, accName, accRole);
                    if (objReturn != default(IAccessible))
                    {
                        return(objReturn);
                    }
                }
            }
            return(objReturn);
        }
コード例 #12
0
 public static IEnumerable<IAccessible> FindDescendantsByRole(this IAccessible element, AccRole role)
 {
     return GetDescendants(element);
 }
コード例 #13
0
 public static bool IsRoleSafe(this IAccessible element, AccRole role)
 {
     var actualRole = element.GetRoleSafe();
      return actualRole == default(AccRole) || actualRole == role;
 }