Example #1
0
        public async Task<ActionResult> Add(UserSelectedViewModel model)
        {
            var getSelectedUsers = model.GetSelectedUsers();

            if (getSelectedUsers.Count == 0)
            {
                this.ModelState.AddModelError(string.Empty, "Трябва да изберете най-малко един учасник.");
                return this.View(model);
            }

            foreach (var participant in getSelectedUsers)
            {
                var currentParticipant = new Participant()
                {
                    RateSystemId = model.RateSystemId,
                    UserId = participant.Id
                };

                this.participants.Add(currentParticipant);
            }

            this.participants.SaveChanges();

            this.AddNotification("Успешно добавихте учасници!", NotificationType.SUCCESS);

            return this.RedirectToAction<UserController>(c => c.Add(model.RateSystemId));
        }
Example #2
0
        public ActionResult Remove(int rateSystemId)
        {
            var users = this.users
                .GetAllSelectUsers(rateSystemId)
                .To<UserViewModel>()
                .ToList();

            var userSelectedVM = new UserSelectedViewModel()
            {
                Users = users,
                RateSystemId = rateSystemId
            };

            return this.View(userSelectedVM);
        }
Example #3
0
        public ActionResult Remove(UserSelectedViewModel model)
        {
            var getSelectedUsers = model.GetSelectedUsers();

            if (getSelectedUsers.Count == 0)
            {
                this.ModelState.AddModelError(string.Empty, "Трябва да изберете най-малко един учасник.");
                return this.View(model);
            }

            foreach (var participant in getSelectedUsers)
            {
                var currentParticipant = this.participants.GetParticipantByRateSystemIdAndUserId(model.RateSystemId, participant.Id);

                if (currentParticipant == null)
                {
                    throw new ArgumentNullException("Participant can not be found!");
                }

                this.participants.Remove(currentParticipant);
            }

            this.participants.SaveChanges();

            return this.RedirectToAction<UserController>(c => c.Remove(model.RateSystemId));
        }