Ejemplo n.º 1
0
        public async Task <IActionResult> GetUsersToAdmin([FromQuery] AdminParams adminParams)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var userFromRepo  = await _repo.GetUser(currentUserId);

            adminParams.UserId = currentUserId;
            if (string.IsNullOrEmpty(adminParams.Gender))
            {
                adminParams.Gender = userFromRepo.Gender == "طالبه"?"طالبه":"'طالبه'";
            }

            if (string.IsNullOrEmpty(adminParams.UserGroupName))
            {
                adminParams.UserGroupName = userFromRepo.UserGroup.UserGroupName;
            }

            if (string.IsNullOrEmpty(adminParams.UserClassName))
            {
                adminParams.UserClassName = userFromRepo.UserClass.UserClassName;
            }

            var users = await _repo.GetUsersToAdmin(adminParams);

            var UserToReturn = _mapper.Map <IEnumerable <UserToAdminListDto> > (users);

            Response.AddPagination(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages);
            return(Ok(UserToReturn));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetUserList([FromQuery] AdminParams adminParams)
        {
            var usersFromRepo = await _dbContext.Users.Include(u => u.UserRoles).ToListAsync();

            if (usersFromRepo.Any())
            {
                if (Int32.TryParse(adminParams.PageSize.ToString(), out int size) && Int32.TryParse(adminParams.PageNumber.ToString(), out int part))
                {
                    var usersToReturn = usersFromRepo.Skip(part * size).Take(size).Select(x => new UserForAdminPanelDto
                    {
                        Username  = x.UserName,
                        UserRoles = _userManager.GetRolesAsync(x).Result,
                        Photo     = x.PhotoUrl
                    });

                    return(Ok(usersToReturn));
                }
                else
                {
                    throw new Exception("invalid params");
                }
            }

            else
            {
                return(NoContent());
            }
        }
Ejemplo n.º 3
0
        public async Task <PagedList <User> > GetUsersToAdmin(AdminParams adminParams)
        {
            var users = _context.Users.Include(p => p.Photos).Include(uc => uc.UserClass)
                        .Include(v => v.UserVillage).Include(c => c.UserCity)
                        .Include(g => g.UserGovernorate).Include(co => co.UserCountry)
                        .Include(p => p.UserPays).Include(e => e.UserExams).Include(co => co.UserGroup)
                        .Include(a => a.UserAttends).OrderByDescending(u => u.ArabicName).AsQueryable();

            users = users.Where(u => u.Id != adminParams.UserId);
            users = users.Where(u => u.Gender == adminParams.Gender);
            users = users.Where(u => u.UserGroup.UserGroupName == adminParams.UserGroupName);
            users = users.Where(u => u.UserClass.UserClassName == adminParams.UserClassName);


            return(await PagedList <User> .CreateAsync(users, adminParams.PageNumber, adminParams.PageSize));
        }
Ejemplo n.º 4
0
        public ActionResult SaveChanges(AdminParams model)
        {
            log.Info("Admin/SaveChanges has been fired.");
            int    N = model.__N;
            int    D = model.__D;
            int    S = model.__S;
            int    G = model.__G;
            int    P = model.__P;
            string C = model.__C;

            if (C == null)
            {
                C = "";
            }
            float T       = model.__T;
            bool  success = false;

            //URADITI TACNU proveru redosleda

            /*
             * if (S != AdminParams.S)
             * {
             *  if (G != AdminParams.G)
             *  {
             *      if (G < S)
             *      {
             *          return RedirectToAction("Index", new { Message = MessageChange.ChangeUnsuccess });
             *      }
             *      if (P != AdminParams.P)
             *      {
             *          if (P < G)
             *          {
             *              return RedirectToAction("Index", new { Message = MessageChange.ChangeUnsuccess });
             *          }
             *          else
             *          {
             *              AdminParams.P = P;
             *          }
             *      }
             *      AdminParams.G = G;
             *  }
             *  else if (P != AdminParams.P)
             *  {
             *      if (P < S)
             *      {
             *          return RedirectToAction("Index", new { Message = MessageChange.ChangeUnsuccess });
             *      }
             *      AdminParams.P = P;
             *  }
             *  AdminParams.S = S;
             *  success = true;
             * }
             * else if (G != AdminParams.G)
             * {
             *  if (P != AdminParams.P)
             *  {
             *      if (P < G)
             *      {
             *          return RedirectToAction("Index", new { Message = MessageChange.ChangeUnsuccess });
             *      }
             *      else
             *      {
             *          AdminParams.P = P;
             *      }
             *  }
             *  AdminParams.G = G;
             *  success = true;
             * }
             * else if (P != AdminParams.P)
             * {
             *  //provera da li je vece od G paketa
             *  if (P < G)
             *  {
             *      return RedirectToAction("Index", new { Message = MessageChange.ChangeUnsuccess });
             *  }
             *  else
             *  {
             *      AdminParams.P = P;
             *  }
             *  success = true;
             * }
             */
            if ((S < G) && (G < P))
            {
                if ((P != AdminParams.P) || (AdminParams.S != S) || (AdminParams.G != G))
                {
                    success = true;
                }
                AdminParams.P = P;
                AdminParams.G = G;
                AdminParams.S = S;
            }
            else
            {
                return(RedirectToAction("Index", new { Message = MessageChange.ChangeUnsuccess }));
            }

            //trebalo bui da je dobro
            if (N != AdminParams.N)
            {
                AdminParams.N = N;
                success       = true;
            }
            if (D != AdminParams.D)
            {
                AdminParams.D = D;
                success       = true;
            }
            if (T != AdminParams.T)
            {
                AdminParams.T = T;
                success       = true;
            }
            if (!AdminParams.C.Equals(C))
            {
                if (!C.Equals(""))
                {
                    AdminParams.C = C;
                    success       = true;
                }
            }
            if (success)
            {
                return(RedirectToAction("Index", new { Message = MessageChange.ChangeSuccess }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }