public ActionResult AddExistingUser(Workers frm) { var uRepo = new UsersRepo(); var usr = uRepo.GetById(frm.UserId); ViewBag.SeasonId = frm.SeasonId; if (usr == null || usr.FullName != frm.FullName) { ModelState.AddModelError("FullName", Messages.UserNotExists); return(PartialView("_WorkerList", GetWorkerVMByRelevantEntity(frm.RelevantEntityId, frm.RelevantEntityLogicalName, frm.SeasonId, frm.LeagueId))); } var uJob = new UsersJob { JobId = frm.JobId, UserId = usr.UserId, SeasonId = frm.SeasonId, LeagueId = (frm.LeagueId == 0 ? (int?)null : frm.LeagueId) }; switch (frm.RelevantEntityLogicalName) { case LogicaName.Union: uJob.UnionId = frm.RelevantEntityId; break; case LogicaName.League: uJob.LeagueId = frm.RelevantEntityId; break; case LogicaName.Team: uJob.TeamId = frm.RelevantEntityId; break; case LogicaName.Club: uJob.ClubId = frm.RelevantEntityId; break; } var jobsRepo = new JobsRepo(); if (jobsRepo.IsUserInJob(frm.RelevantEntityLogicalName, frm.RelevantEntityId, uJob.JobId, usr.UserId)) { ModelState.AddModelError("FullName", Messages.UserAlreadyHasThisRole); return(PartialView("_WorkerList", GetWorkerVMByRelevantEntity(frm.RelevantEntityId, frm.RelevantEntityLogicalName, frm.SeasonId, frm.LeagueId))); } jobsRepo.AddUsersJob(uJob); jobsRepo.Save(); TempData["SavedId"] = uJob.UserId; return(PartialView("_WorkerList", GetWorkerVMByRelevantEntity(frm.RelevantEntityId, frm.RelevantEntityLogicalName, frm.SeasonId, frm.LeagueId))); }