Ejemplo n.º 1
0
        public async Task <ActionResult> JoinRace(HomeViewModel model)
        {
            if (ModelState.IsValid)
            {
                string userId = this.User.Identity.GetUserId();
                DriversRepository <Driver, DriverDTO> driversRepo = new DriversRepository <Driver, DriverDTO>();
                Driver driver = driversRepo.GetForUser(userId);

                if (Request.Form["new_driver"] != null)
                {
                    driver = new Driver()
                    {
                        ApplicationUserId = userId,
                        CarId             = model.SelectedCarId,
                        ControllerId      = Convert.ToInt32(model.SelectedControllerId),
                        TrackId           = model.SelectedTrackId
                    };

                    driver = await driversRepo.Insert(driver);
                }
                else if (Request.Form["change_driver"] != null)
                {
                    driver.CarId        = model.SelectedCarId;
                    driver.ControllerId = Convert.ToInt32(model.SelectedControllerId);
                    driver.TrackId      = model.SelectedTrackId;
                    EntityState state = await driversRepo.Update(driver.Id, driver);
                }
                else if (Request.Form["delete_driver"] != null)
                {
                    await driversRepo.Delete(driver.Id);
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> DeleteDriver(string userId)
        {
            DriversRepository <Driver, DriverDTO> driversRepo = new DriversRepository <Driver, DriverDTO>();
            Driver driver = driversRepo.GetForUser(userId);

            if (driver == null)
            {
                return(NotFound());
            }

            await driversRepo.Delete(driver.Id);

            return(Ok(Mapper.Map <DriverDTO>(driver)));
        }
            public async Task <IHttpActionResult> PostDriverResult(DriverResultDTO driverResultDTO)
            {
                DriverResult driverResult = Mapper.Map <DriverResult>(driverResultDTO);

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

                driverResult = await repo.Insert(driverResult);

                // Remove this driver from registered drivers
                DriversRepository <Driver, DriverDTO> driversRepo = new DriversRepository <Driver, DriverDTO>();
                Driver driver = driversRepo.GetForUser(driverResult.ApplicationUserId);

                if (driver != null)
                {
                    await driversRepo.Delete(driver.Id);
                }

                return(CreatedAtRoute("DefaultApi", new { id = driverResult.Id }, Mapper.Map <DriverResultDTO>(driverResult)));
            }