Ejemplo n.º 1
0
        // GET: Entries/Create
        public ActionResult Create()
        {
            EntryCreateViewModel entryCreateViewModel = new EntryCreateViewModel();

            var boatList    = new List <BoatDropDownListViewModel>();
            var clubList    = new List <ClubDropDownListViewModel>();
            var regattaList = new List <RegattaDropDownListViewModel>();

            var mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <BoatDTO, BoatDropDownListViewModel>();
                cfg.CreateMap <ClubDTO, ClubDropDownListViewModel>();
                cfg.CreateMap <RegattaDTO, RegattaDropDownListViewModel>();
            });

            using (var boatService = new BoatService())
                using (var clubService = new ClubService())
                    using (var regattaService = new RegattaService())
                    {
                        try
                        {
                            var allBoatsDto = boatService.EagerDisconnectedService.GetAll().Where(x => x.Active);
                            if (allBoatsDto == null)
                            {
                                throw new NullReferenceException();
                            }
                            var mapper = mapperConfig.CreateMapper();
                            mapper.Map(allBoatsDto, boatList);

                            var allclubsDto = clubService.EagerDisconnectedService.FindByInclude(x => x.Active);
                            if (allclubsDto == null)
                            {
                                throw new NullReferenceException();
                            }
                            var mapper2 = mapperConfig.CreateMapper();
                            mapper.Map(allclubsDto, clubList);

                            var allregattasDto = regattaService.EagerDisconnectedService.FindByInclude(x => x.Active);
                            if (allregattasDto == null)
                            {
                                throw new NullReferenceException();
                            }
                            var mapper3 = mapperConfig.CreateMapper();
                            mapper.Map(allregattasDto, regattaList);

                            ViewBag.BoatDropDownList    = new SelectList(boatList.OrderBy(b => b.FullBoatName), "Id", "FullBoatName");
                            ViewBag.ClubDropDownList    = new SelectList(clubList.OrderBy(c => c.Name), "Id", "Name");
                            ViewBag.RegattaDropDownList = new SelectList(regattaList.OrderBy(c => c.Name), "Id", "Name");

                            return(View());
                        }
                        catch (Exception e)
                        {
                            TempData["ResultMessage"] = e.Message;
                            return(View("Error"));
                        }
                    }
        }
Ejemplo n.º 2
0
        public IHttpActionResult PostEntry(EntryCreateViewModel vm)
        {
            var entry = AutoMapper.Mapper.Map <EntryCreateViewModel, Entry>(vm);

            db.Players.Attach(entry.Player);

            foreach (var team in entry.Teams)
            {
                db.Teams.Attach(team);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Entries.Add(entry);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = entry.EntryID }, entry));
        }
Ejemplo n.º 3
0
 public ActionResult Create(EntryCreateViewModel entryCreateViewModel)
 {
     try
     {
         EntryDTO entryDto = new EntryDTO(entryCreateViewModel.EntryNo, entryCreateViewModel.EntryName, DateTime.Now, 0, entryCreateViewModel.BoatId, entryCreateViewModel.RegattaId, entryCreateViewModel.ClubRepresentationId);
         UserDTO  user;
         using (var userService = new UserService())
         {
             var loginUser = Session["Login"].ToString();
             user = userService.EagerDisconnectedService.FindBy(u => u.Login == loginUser).First();
         }
         using (var entryService = new EntryService())
         {
             entryService.EagerDisconnectedService.Add(user, entryDto);
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         TempData["ResultMessage"] = e.Message;
         return(View("Error"));
     }
 }