Ejemplo n.º 1
0
        public ActionResult CreateRide(RidesModel ride, string timeFrom, string dateFrom, string selectedCar, string steps, string price, string distance)
        {
            ErrorEnum error;

            //Mantem sessão
            var userModel = UserManager.RetrieveUser(ride.DonorID, out error);

            var datetimeFrom = new DateTime(Int32.Parse(dateFrom.Substring(6, 4)),
                                            Int32.Parse(dateFrom.Substring(3, 2)), Int32.Parse(dateFrom.Substring(0, 2)),
                                            Int32.Parse(timeFrom.Substring(0, 2)), Int32.Parse(timeFrom.Substring(3, 2)), 0);

            ride.Car = new CarModel {
                ID = new Guid(selectedCar)
            };
            ride.Price     = Convert.ToDecimal(price);
            ride.Direction = new DirectionsModel(steps);
            ride.TimeFrom  = datetimeFrom;
            ride.Distance  = float.Parse(distance, CultureInfo.InvariantCulture);

            var guid = RidesManager.CreateRide(ride, out error);

            //TODO: Mensagem de Criação
            ViewBag.InsertedRide = guid;
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Responsável por criar uma nova carona
        /// </summary>
        /// <param name="ride"></param>
        /// <param name="error"></param>
        public static Guid CreateRide(RidesModel ride, out ErrorEnum error)
        {
            DBConfigurations database = new DBConfigurations();

            error = ErrorEnum.NoErrors;
            var rideDTO = Conversor.RidesModelToDTO(ride);

            rideDTO.ID             = Guid.NewGuid();
            rideDTO.RemainingSeats = rideDTO.Seats;             //se foi recém criada, tem todos os assentos disponíveis
            database.Ride.Add(rideDTO);
            database.SaveChanges();

            int turn = 0;

            foreach (var point in ride.Direction.Path)
            {
                var direction = new Directions
                {
                    ID       = Guid.NewGuid(),
                    Lat      = point.Lat,
                    Long     = point.Long,
                    Position = turn,
                    Ride_ID  = rideDTO.ID
                };
                turn++;
                database.Directions.Add(direction);
            }
            database.SaveChanges();
            return(rideDTO.ID);
        }
Ejemplo n.º 3
0
        public ActionResult CreateRide()
        {
            ErrorEnum error;
            var       userModel = UserManager.RetrieveUser(new Guid(User.Identity.Name), out error);
            var       newRide   = new RidesModel
            {
                DonorID   = userModel.ID,
                DonorName = userModel.FullName
            };

            return(View("CreateRide", newRide));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retorna um tipo Model a partir do DTO de Rides
        /// </summary>
        /// <param name="dto">DTO a ser convertido</param>
        /// <returns>RidesModel respectivo</returns>
        public static RidesModel RidesToModel(Rides dto)
        {
            RidesModel model = new RidesModel
            {
                Car             = CarsManager.RetrieveCar(dto.Car_ID),
                DonorID         = dto.DonorID,
                DonorName       = dto.DonorName,
                FromPlace       = dto.FromPlace,
                GiveUpTolerance = dto.GiveUpTolerance,
                ID             = dto.ID,
                Message        = dto.Message,
                Price          = dto.Price,
                Seats          = dto.Seats,
                TimeFrom       = dto.TimeFrom,
                ToPlace        = dto.ToPlace,
                TrunkSize      = dto.TrunkSize,
                RemainingSeats = dto.RemainingSeats,
                Distance       = dto.Distance
            };

            return(model);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Retorna um tipo Ride DTO a partir do seu model
        /// </summary>
        /// <param name="model">Model a ser convertido</param>
        /// <returns>DTO de Ride</returns>
        public static Rides RidesModelToDTO(RidesModel model)
        {
            Rides dto = new Rides
            {
                Car_ID          = model.Car.ID,
                DonorID         = model.DonorID,
                DonorName       = model.DonorName,
                FromPlace       = model.FromPlace,
                GiveUpTolerance = model.GiveUpTolerance,
                ID             = model.ID,
                Message        = model.Message,
                Price          = model.Price,
                Seats          = (int)model.Seats,
                TimeFrom       = (DateTime)model.TimeFrom,
                ToPlace        = model.ToPlace,
                TrunkSize      = model.TrunkSize,
                RemainingSeats = model.RemainingSeats,
                Distance       = model.Distance
            };

            return(dto);
        }