Beispiel #1
0
        public async Task <IActionResult> AddAward()
        {
            List <Award> awards = await _awardLogic.GetAwardsAsync();

            if (User.IsInRole("User"))
            {
                ViewBag.Awards = new SelectList(awards
                                                .Where(a => a.AwardType == AwardType.Thanks)
                                                .Select(a => a.AwardTitle)
                                                .OrderBy(a => a)
                                                .ToArray());
            }
            else
            {
                ViewBag.Awards = new SelectList(awards
                                                .Select(a => a.AwardTitle)
                                                .OrderBy(a => a)
                                                .ToArray());
            }

            List <User> users = await _userLogic.GetUsersAsync();

            var recepients = users
                             .Where(u => u.Email != User.Identity.Name && u.Status != Status.Special)
                             .Select(u => u.Email)
                             .OrderBy(u => u)
                             .ToArray();

            string[] usersFrom;
            if (User.IsInRole("User"))
            {
                usersFrom = users
                            .Where(u => u.Email == User.Identity.Name)
                            .Select(u => u.Email)
                            .OrderBy(u => u)
                            .ToArray();
            }
            else
            {
                usersFrom = users
                            .Where(u => u.Email == User.Identity.Name || u.Status == Status.Special)
                            .Select(u => u.Email)
                            .OrderBy(u => u)
                            .ToArray();
            }

            ViewBag.Recepients = new SelectList(recepients);
            ViewBag.UsersFrom  = new SelectList(usersFrom);

            AddAwardModel model = new AddAwardModel
            {
                FromEmail = usersFrom.FirstOrDefault(u => u == User.Identity.Name)
            };

            return(PartialView("_AddAwardPartial", model));
        }