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))); }
public ActionResult CreateWorker(CreateWorkerForm frm) { if (usersRepo.GetByIdentityNumber(frm.IdentNum) != null) { var tst = Messages.IdIsAlreadyExists; tst = string.Format(tst, "\""); ModelState.AddModelError("IdentNum", tst); } if (usersRepo.GetByEmail(frm.Email) != null) { var tst = Messages.EmailAlreadyExists; tst = string.Format(tst, "\""); ModelState.AddModelError("Email", tst); } switch (frm.RelevantEntityLogicalName) { case LogicaName.Union: frm.JobsList = new SelectList(jobsRepo.GetByUnion(frm.RelevantEntityId), "JobId", "JobName"); break; case LogicaName.League: frm.JobsList = new SelectList(jobsRepo.GetByLeague(frm.RelevantEntityId), "JobId", "JobName"); break; case LogicaName.Team: frm.JobsList = new SelectList(jobsRepo.GetByTeam(frm.RelevantEntityId), "JobId", "JobName"); break; case LogicaName.Club: frm.JobsList = new SelectList(jobsRepo.GetClubJobs(frm.RelevantEntityId), "JobId", "JobName"); break; default: frm.JobsList = new List <SelectListItem>(); break; } if (ModelState.IsValid) { var user = new User(); UpdateModel(user); user.Password = Protector.Encrypt(frm.Password); user.TypeId = 3; usersRepo.Create(user); var uJob = new UsersJob { JobId = frm.JobId, UserId = user.UserId, SeasonId = frm.SeasonId }; 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 jRepo = new JobsRepo(); jRepo.AddUsersJob(uJob); jRepo.Save(); ViewBag.SeasonId = frm.SeasonId; TempData["WorkerAddedSuccessfully"] = true; } return(PartialView("_CreateWorker", frm)); }