Example #1
0
        public ActionResult Index()
        {
            ImplantationDTO implantation = new ImplantationDTO();

            implantation.Episode.Active = true;

            ViewBag.NumberOfWorkerTypes = WorkerTypeRepository.Instance.GetCountFromFirm(CurrentFirm.ExternalId);

            ViewBag.WorkerType = WorkerTypeRepository.Instance.GetAllFromFirm(CurrentFirm.ExternalId);

            ViewBag.Icons = Enum.GetValues(typeof(Icons)).Cast <Icons>().Select(i => new SelectListItem
            {
                Text  = i.ToString(),
                Value = i.ToString()
            }).ToList();

            ViewBag.Profiles = GetProfilesToSelect(new Profiles());

            ViewBag.NumberOfWorkers = WorkerRepository.Instance.GetCountFromFirm(CurrentFirm.Id);

            ViewBag.Types = GetWorkerTypesToSelect(0);

            ViewBag.Sponsors = GetSponsorsToSelect();
            ViewBag.Episodes = GetEpisodesToSelect();

            ViewBag.SubTeams = JsonConvert.SerializeObject(new List <string>());

            return(View("Index", implantation));
        }
Example #2
0
        public ActionResult SaveEpisode(ImplantationDTO implantation)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (implantation.Episode.Active == false)
                    {
                        Success("Campanha não pode ser alterada.");
                    }
                    else
                    {
                        if (implantation.Episode.Id == null || implantation.Episode.Id.Equals(""))
                        {
                            implantation.Episode.Active = true;
                        }


                        implantation.Episode.initDate = implantation.Episode.initDateAux.Ticks;

                        implantation.Episode.finishDate = implantation.Episode.finishDateAux.Ticks;

                        implantation.Episode.GameId = CurrentFirm.ExternalId;

                        ValidateModel(implantation.Episode);

                        EpisodeEngineDTO newEpisode = EpisodeEngineService.Instance.CreateOrUpdate(implantation.Episode);

                        if (newEpisode == null)
                        {
                            throw new Exception(".");
                        }

                        Success("Campanha atualizada com sucesso.");

                        return(View("Index", implantation));
                    }
                }
                else
                {
                    implantation.Episode.Active = true;

                    ViewBag.Icons = Enum.GetValues(typeof(Icons)).Cast <Icons>().Select(i => new SelectListItem
                    {
                        Text  = i.ToString(),
                        Value = i.ToString()
                    }).ToList();
                    ModelState.AddModelError("", "Alguns campos são obrigatórios para salvar a Campanha.");

                    return(View("Index", implantation));
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);

                Error("Erro ao atualizar campanha" + ex.Message);
                return(View("Index"));
            }

            return(new EmptyResult());
        }
Example #3
0
        public ActionResult SaveWorkerType(ImplantationDTO implantation)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    ViewBag.Profiles = GetProfilesToSelect(implantation.WorkerType.ProfileName);

                    if (ModelState.IsValid)
                    {
                        if (implantation.WorkerType.Id > 0)
                        {
                            implantation.WorkerType.Status         = GenericStatus.ACTIVE;
                            implantation.WorkerType.FirmId         = CurrentFirm.Id;
                            implantation.WorkerType.ExternalFirmId = CurrentFirm.ExternalId;
                            implantation.WorkerType.UpdatedBy      = CurrentUserId;

                            ValidateModel(implantation.WorkerType);

                            WorkerTypeRepository.Instance.UpdateWorkerType(implantation.WorkerType);

                            Success("Função atualizada com sucesso.");
                            scope.Complete();
                        }
                        else
                        {
                            implantation.WorkerType.Status         = GenericStatus.ACTIVE;
                            implantation.WorkerType.FirmId         = CurrentFirm.Id;
                            implantation.WorkerType.ExternalFirmId = CurrentFirm.ExternalId;
                            implantation.WorkerType.UpdatedBy      = CurrentUserId;

                            ValidateModel(implantation.WorkerType);

                            WorkerTypeRepository.Instance.CreateWorkerType(implantation.WorkerType);

                            Success("Função criada com sucesso.");
                            scope.Complete();
                        }
                        ViewBag.NumberOfWorkerTypes = WorkerTypeRepository.Instance.GetCountFromFirm(CurrentFirm.ExternalId);

                        ViewBag.WorkerType = WorkerTypeRepository.Instance.GetAllFromFirm(CurrentFirm.ExternalId);

                        ViewBag.Icons = Enum.GetValues(typeof(Icons)).Cast <Icons>().Select(i => new SelectListItem
                        {
                            Text  = i.ToString(),
                            Value = i.ToString()
                        }).ToList();

                        ViewBag.Profiles = GetProfilesToSelect(new Profiles());

                        ViewBag.NumberOfWorkers = WorkerRepository.Instance.GetCountFromFirm(CurrentFirm.Id);

                        ViewBag.Types = GetWorkerTypesToSelect(0);

                        ViewBag.Sponsors = GetSponsorsToSelect();
                        ViewBag.Episodes = GetEpisodesToSelect();

                        ViewBag.SubTeams = JsonConvert.SerializeObject(new List <string>());
                        return(View("Index", implantation));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Alguns campos são obrigatórios para salvar a Função.");

                        return(View("Index", implantation));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);

                ModelState.AddModelError("", "Ocorreu um erro ao tentar salvar a Função.");

                return(View("Index", implantation));
            }

            return(new EmptyResult());
        }