Ejemplo n.º 1
0
        public async Task <ResultModel> CreateVehicleLocation(VehicleLocationVm vehicleLocationVm)
        {
            try
            {
                var entity = new Domain.Entities.VehicleLocation
                {
                    Latitude  = vehicleLocationVm.Latitude,
                    Longitude = vehicleLocationVm.Longitude,
                    TripDate  = vehicleLocationVm.TripDate,
                    TripTime  = vehicleLocationVm.TripTime,
                    Speed     = vehicleLocationVm.Speed,
                    Altitude  = vehicleLocationVm.Altitude,
                    VehicleId = vehicleLocationVm.VehicleId
                };


                await _context.VEHICLE_LOCATION.AddAsync(entity);

                await _context.SaveChangesAsync();

                return(new ResultModel
                {
                    Result = true,
                    Message = NotificationConfig.InsertSuccessMessage($"{vehicleLocationVm.VehicleId}"),
                    Id = entity.VehicleLocationId.ToString()
                });
            }

            catch (Exception)
            {
                return(new ResultModel {
                    Result = false, Message = NotificationConfig.InsertErrorMessage($"{vehicleLocationVm.VehicleId}")
                });
            }
        }
Ejemplo n.º 2
0
        public async Task <ResultModel> UpdateVehicleLocation(UpdateVehicleLocationVm updateVehicleLocationVm)
        {
            try
            {
                if (updateVehicleLocationVm.VehicleLocationId > 0)
                {
                    var entity = new Domain.Entities.VehicleLocation
                    {
                        VehicleLocationId = updateVehicleLocationVm.VehicleLocationId,
                        Latitude          = updateVehicleLocationVm.Latitude,
                        Longitude         = updateVehicleLocationVm.Longitude,
                        TripDate          = updateVehicleLocationVm.TripDate,
                        TripTime          = updateVehicleLocationVm.TripTime,
                        Speed             = updateVehicleLocationVm.Speed,
                        Altitude          = updateVehicleLocationVm.Altitude,
                        VehicleId         = updateVehicleLocationVm.VehicleId
                    };

                    _context.VEHICLE_LOCATION.Update(entity);
                    await _context.SaveChangesAsync();

                    return(new ResultModel {
                        Result = true, Message = NotificationConfig.UpdateSuccessMessage($"{updateVehicleLocationVm.VehicleId}"), Id = entity.VehicleLocationId.ToString()
                    });
                }
                else
                {
                    return(new ResultModel {
                        Result = false, Message = NotificationConfig.NotFoundMessage($"{updateVehicleLocationVm.VehicleId} information")
                    });
                }
            }

            catch (Exception)
            {
                return(new ResultModel {
                    Result = false, Message = NotificationConfig.UpdateErrorMessage($"{updateVehicleLocationVm.VehicleId}")
                });
            }
        }