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)); }
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)); }