Example #1
0
        public ActionResult CreateWorker(int relevantEntityId, LogicaName logicalName, int seasonId)
        {
            var frm = new CreateWorkerForm
            {
                RelevantEntityId          = relevantEntityId,
                RelevantEntityLogicalName = logicalName,
                SeasonId = seasonId
            };

            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;
            }
            frm.IsActive = true;
            return(PartialView("_CreateWorker", frm));
        }
Example #2
0
        // CRUD Worker
        public ActionResult EditWorker(int id, int relevantEntityId, LogicaName logicalName, int seasonId, int?leagueId)
        {
            var frm = new CreateWorkerForm
            {
                RelevantEntityId          = relevantEntityId,
                RelevantEntityLogicalName = logicalName,
            };

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

            UsersJob userJob = jobsRepo.GetUsersJobById(id);

            frm.InjectFrom(userJob.User);
            frm.JobId     = userJob.JobId;
            frm.UserJobId = userJob.Id;
            frm.SeasonId  = seasonId;
            if (!string.IsNullOrEmpty(userJob.User.Password))
            {
                frm.Password = Protector.Decrypt(userJob.User.Password);
            }
            return(PartialView("_EditWorker", frm));
        }
Example #3
0
        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));
        }
Example #4
0
        public ActionResult EditWorker(CreateWorkerForm frm)
        {
            User     user    = usersRepo.GetById(frm.UserId);
            UsersJob userJob = jobsRepo.GetUsersJobById(frm.UserJobId);

            if (user == null)
            {
                string err = Messages.UserNotExists;
                ModelState.AddModelError("FullName", err);
            }

            if (userJob == null)
            {
                string err = Messages.RoleNotExists;
                ModelState.AddModelError("UserJob", err);
            }

            if (usersRepo.GetByIdentityNumber(frm.IdentNum) != null && frm.IdentNum != user.IdentNum)
            {
                string tst = Messages.IdIsAlreadyExists;
                tst = String.Format(tst, "\"");
                ModelState.AddModelError("IdentNum", tst);
            }

            if (usersRepo.GetByEmail(frm.Email) != null && frm.Email != user.Email)
            {
                string tst = Messages.EmailAlreadyExists;
                tst = string.Format(tst, "\"");
                ModelState.AddModelError("Email", tst);
            }

            bool isUserInJob = jobsRepo.IsUserInJob(frm.RelevantEntityLogicalName, frm.RelevantEntityId, frm.JobId, userJob.UserId);

            if (isUserInJob && userJob.JobId != frm.JobId)
            {
                ModelState.AddModelError("JobId", Messages.UserAlreadyHasThisRole);
            }

            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)
            {
                UpdateModel(user);
                user.Password = Protector.Encrypt(frm.Password);
                usersRepo.Save();

                userJob.SeasonId = frm.SeasonId;
                UpdateModel(userJob);
                userJob.LeagueId = (userJob.LeagueId == 0 ? (int?)null : userJob.LeagueId);
                jobsRepo.Save();

                TempData["WorkerAddedSuccessfully"] = true;
            }

            return(PartialView("_EditWorker", frm));
        }