public ActionResult Add(SeasonAddViewModel viewModel) { if (viewModel.Year < DateTime.Now.Year) { AddModelError(viewModel, m => m.Year, Dom.Translation.Common.YearLessCurrentYear); } if (ModelState.IsValid) { Season season = Season.Empty(); season.Year = viewModel.Year; season.SeasonTypeId = viewModel.SeasonTypeId; EntityContext.AddEntityProgress( season.EntityInfo, new EntityProgress { OrganizationId = viewModel.OrganizationId, EntityStateAfterId = Dom.EntityType.Season.State.Created } ); EntityContext.AddEntityOrganization( season.EntityInfo, viewModel.OrganizationId, Dom.EntityType.Season.State.Created ); _seasonRepository.AddOrUpdate(season); _seasonRepository.UnitOfWork.SaveChanges(); return(RedirectToAction(Mvc.Controller.Season.List, Mvc.Controller.Season.Name)); } ICollection <SelectListItemCount> organizationItems = _organizationRepository.GetOrganizations( UserContext.User.Id, UserContext.User.OrganizationId, new List <int> { Dom.OrganizationType.Club } ); viewModel.OrganizationItems = Mapper.Map <ICollection <SelectListItem> >(organizationItems); viewModel.SeasonTypeItems = InitSeasonTypeSelectListItems(); return(View(Mvc.View.Season.Add, viewModel)); }
public ActionResult Add() { ICollection <SelectListItemCount> organizationItems = _organizationRepository.GetOrganizations( UserContext.User.Id, UserContext.User.OrganizationId, new List <int> { Dom.OrganizationType.Club } ); var viewModel = new SeasonAddViewModel { SeasonTypeItems = InitSeasonTypeSelectListItems(), OrganizationItems = Mapper.Map <ICollection <SelectListItem> >(organizationItems), Year = DateTime.UtcNow.Year }; if (organizationItems.FirstOrDefault(m => m.Value == UserContext.User.OrganizationId) != null) { viewModel.OrganizationId = UserContext.User.OrganizationId; } return(View(Mvc.View.Season.Add, viewModel)); }