Ejemplo n.º 1
0
        public ActionResult Add(RaceAddViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Race race = Race.Empty();
                race.Name       = viewModel.Name;
                race.RaceTypeId = viewModel.RaceTypeId;
                race.PointId    = viewModel.PointId;
                race.SeasonId   = viewModel.SeasonId;

                EntityContext.AddEntityProgress(
                    race.EntityInfo,
                    new EntityProgress
                {
                    OrganizationId     = viewModel.OrganizationId,
                    EntityStateAfterId = Dom.EntityType.Race.State.Created
                }
                    );
                EntityContext.AddEntityOrganization(
                    race.EntityInfo,
                    viewModel.OrganizationId,
                    Dom.EntityType.Race.State.Created
                    );
                _raceRepository.AddOrUpdate(race);
                _raceRepository.UnitOfWork.SaveChanges();

                return(RedirectToAction(Mvc.Controller.Race.List, Mvc.Controller.Race.Name));
            }

            ICollection <SelectListItemCount> organizationItems = _organizationRepository.GetOrganizations(
                UserContext.User.Id,
                UserContext.User.OrganizationId,
                new List <int> {
                Dom.OrganizationType.Club
            }
                );

            if (viewModel.OrganizationId != 0)
            {
                var points = _pointRepository.GetPoints(UserContext.User.Id, UserContext.User.OrganizationId, viewModel.OrganizationId);
                viewModel.PointItems = Mapper.Map <ICollection <SelectListItem> >(points);
                var seasons = _seasonRepository.GetSeasons(UserContext.User.Id, UserContext.User.OrganizationId, viewModel.OrganizationId);
                viewModel.SeasonItems = Mapper.Map <ICollection <SelectListItem> >(seasons);
            }

            viewModel.OrganizationItems = Mapper.Map <ICollection <SelectListItem> >(organizationItems);
            viewModel.RaceTypeItems     = InitRaceTypeSelectListItems();

            return(View(Mvc.View.Race.Add, viewModel));
        }