Example #1
0
 public IActionResult UpdateCarModel(int id, [FromBody] CarModelDTO model)
 {
     try
     {
         if (model == null)
         {
             return(BadRequest("Object is null"));
         }
         var modelEntity = _repository.CarModel.GetById(id);
         if (modelEntity == null)
         {
             Log.Error("Car model with Id: " + id + " not found");
             return(NotFound());
         }
         Mapping.Mapper.Map(model, modelEntity);
         _repository.CarModel.UpdateCarModel(modelEntity);
         _repository.Save();
         return(Ok(modelEntity));
     }
     catch (Exception ex)
     {
         Log.Error("Server error: " + ex.Message);
         return(StatusCode(500, "Server Error"));
     }
 }
Example #2
0
        private void addNewModel_Click(object sender, System.EventArgs e)
        {
            int    brandId             = Convert.ToInt32(CarBrandCB.SelectedValue);
            string newModelDescription = modelInput.Text;

            if (newModelDescription != null && newModelDescription != "" && brandId > 0)
            {
                CarModelDTO dto = new CarModelDTO();
                CarBrandCB.ValueMember = "id";
                dto.ParentBrandId      = brandId;
                CarBrandCB.ValueMember = "description";
                dto.ParentBrand        = Convert.ToString(CarBrandCB.SelectedValue);
                dto.ModelDescription   = newModelDescription;
                dto.Status             = true;

                if (modelCRUD.AddNewModel(dto))
                {
                    MessageBox.Show("Agregado");
                    refreshDataView("model");
                }
            }
            else
            {
                MessageBox.Show("Favor completar el campo modelo y marca a la que pertence para agregar.");
            }
        }
Example #3
0
        public ActionResult _ListCars(string licencePlate)
        {
            List <CarDTO> _cars = new List <CarDTO>();

            if (string.IsNullOrWhiteSpace(licencePlate))
            {
                _cars = carLogic.List();
            }
            else
            {
                _cars = carLogic.List(licencePlate);
            }

            List <Tuple <CarDTO, CarModelDTO, CarMakeDTO> > cars = new List <Tuple <CarDTO, CarModelDTO, CarMakeDTO> >();


            foreach (CarDTO car in _cars)
            {
                CarModelDTO carModel = carModelLogic.Get(car.id_Car_Model);
                CarMakeDTO  carMake  = carMakeLogic.Get(carModel.id_Car_Make);

                cars.Add(new Tuple <CarDTO, CarModelDTO, CarMakeDTO>(car, carModel, carMake));
            }

            CarIndexListCarViewsModel vm = new CarIndexListCarViewsModel
            {
                Cars = cars
            };

            return(PartialView(vm));
        }
Example #4
0
        public void CreateCarModel(CarModelDTO item)
        {
            var mapper = new MapperConfiguration(cg => cg.CreateMap <CarModelDTO, CarModel>()).CreateMapper();
            var model  = mapper.Map <CarModelDTO, CarModel>(item);

            Db.CarModels.Create(model);
            Db.Save();
        }
Example #5
0
 private void FillCarModelDtoParams(CarModelDTO carModel)
 {
     cmd.Parameters.AddWithValue("@CarModelDesId", carModel.ModelId);
     cmd.Parameters.AddWithValue("@CarModelDes", carModel.ModelDescription);
     cmd.Parameters.AddWithValue("@CarBrandId", carModel.ParentBrandId);
     cmd.Parameters.AddWithValue("@CarBrand", carModel.ParentBrand);
     cmd.Parameters.AddWithValue("@status", carModel.Status ? 1 : 0);
 }
Example #6
0
        public CarModelEditForm(CarModelDTO carModel)
        {
            InitializeComponent();
            FillBrandCB();

            modelIdTB.Text           = "" + carModel.ModelId;
            modeloTB.Text            = carModel.ModelDescription;
            CarBrandCB.SelectedValue = carModel.ParentBrandId;
            statusCheck.Checked      = carModel.Status;
        }
Example #7
0
        //Edit
        public void EditCarModel(CarModelDTO dto)
        {
            cmd.Connection  = conexion.AbrirConexion();
            cmd.CommandText = "update car_model set description = @CarModelDes, car_brand_id = @CarBrandId, car_brandDes = @CarBrand, status = @status where id = @CarModelDesId";
            cmd.CommandType = CommandType.Text;

            FillCarModelDtoParams(dto);

            cmd.ExecuteNonQuery();

            cmd.Parameters.Clear();
            conexion.CerrarConexion();
        }
        public async Task <ActionResult <CarModelDTO> > UpdateCarModelAsync(CarModelDTO data)
        {
            try
            {
                var res = await carModelService.UpdateCarModelAsync(data);

                return(Ok(res));
            }
            catch
            {
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task <CarModelDTO> UpdateCarModelAsync(CarModelDTO data)
        {
            var model = await _db.CarModels.FindAsync(data.Id);

            model.Name           = data.Name ?? model.Name;
            model.Year           = data.Year ?? model.Year;
            model.ManufacturerId = data.ManufacturerId ?? model.ManufacturerId;

            var saved = await _db.SaveChangesAsync();

            if (saved <= 0)
            {
                throw new Exception("Problem saving data");
            }

            return(MapToDTO(model));
        }
Example #10
0
        //Edit
        private void iconButton1_Click(object sender, EventArgs e)
        {
            CarModelDTO carModel = new CarModelDTO();

            carModel.ModelId          = Convert.ToInt32(modelIdTB.Text);
            carModel.ModelDescription = modeloTB.Text;
            CarBrandCB.ValueMember    = "description";
            carModel.ParentBrand      = Convert.ToString(CarBrandCB.SelectedValue);
            CarBrandCB.ValueMember    = "id";
            carModel.ParentBrandId    = Convert.ToInt32(CarBrandCB.SelectedValue);
            carModel.Status           = statusCheck.Checked;


            modelCRUD.EditCarModel(carModel);
            MessageBox.Show("Cambios guardados!");
            this.Close();
        }
Example #11
0
        public ActionResult Detail(string licencePlate)
        {
            CarDTO            car      = carLogic.Get(licencePlate);
            CarModelDTO       carModel = carModelLogic.Get(car.id_Car_Model);
            CarMakeDTO        carMake  = carMakeLogic.Get(carModel.id_Car_Make);
            List <BookingDTO> bookings = bookingLogic.List(car.Licence_Plate);
            List <EventDTO>   events   = eventLogic.List(licencePlate);


            CarDetailViewsModel vm = new CarDetailViewsModel
            {
                car      = car,
                carModel = carModel,
                carMake  = carMake,
                events   = events
            };

            return(View(vm));
        }
        public ActionResult AssignationCar(int id)
        {
            BookingAssignationViewsModel vm = new BookingAssignationViewsModel();
            List <CarDTO> _cars             = carLogic.List();
            List <Tuple <CarDTO, CarModelDTO, CarMakeDTO> > cars = new List <Tuple <CarDTO, CarModelDTO, CarMakeDTO> >();
            BookingDTO booking = bookingLogic.GetByRequestBooking(id);

            foreach (CarDTO car in _cars)
            {
                CarModelDTO carModel = carModelLogic.Get(car.id_Car_Model);
                CarMakeDTO  carMake  = carMakeLogic.Get(carModel.id_Car_Make);

                cars.Add(new Tuple <CarDTO, CarModelDTO, CarMakeDTO>(car, carModel, carMake));
            }

            vm.Cars    = cars;
            vm.Booking = booking;

            return(View(vm));
        }
Example #13
0
        public IActionResult Post(int id, [FromBody] CarModelDTO model)
        {
            try
            {
                var manufacturer = _repository.Manufacturer.GetById(id);
                if (manufacturer == null)
                {
                    {
                        Log.Error("Manufacturer not selected");
                        return(BadRequest("Manufacturer does not exist"));
                    }
                }
                if (model == null)
                {
                    Log.Error("Car model object is null");
                    return(BadRequest("Car model is null"));
                }
                if (!ModelState.IsValid)
                {
                    Log.Error("Invalid object sent from client");
                    return(BadRequest("Object validation failed"));
                }

                var modelEntity = Mapping.Mapper.Map <CarModel>(model);

                modelEntity.ManufacturerId = id;

                _repository.CarModel.CreateCarModel(modelEntity);
                _repository.Save();

                var created = Mapping.Mapper.Map <CarModelDTO>(modelEntity);
                return(CreatedAtRoute("GetModel", new { id = created.Id }, created));
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                return(StatusCode(500, "Internal server error"));
            }
        }
Example #14
0
        public List <CarModelDTO> MapToListCarModelDTO(List <CarModel> carModels)
        {
            List <CarModelDTO> retour = new List <CarModelDTO>();

            foreach (CarModel carModel in carModels)
            {
                CarModelDTO newCar = new CarModelDTO
                {
                    //Car = carMapping.MapToListCarDTO(carModel.Car.ToList()),
                    //CarMake = carMakeMapping.MapToCarMakeDTO(carModel.CarMake),
                    Energy      = carModel.Energy,
                    id          = carModel.id,
                    id_Car_Make = carModel.id_Car_Make,
                    Model       = carModel.Model,
                    Places      = carModel.Places
                };

                retour.Add(newCar);
            }

            return(retour);
        }
Example #15
0
        //Add
        public bool AddNewModel(CarModelDTO carModelDTO)
        {
            //Validate duplicates
            if (GetModelByDes(carModelDTO.ModelDescription))
            {
                MessageBox.Show("Este modelo " + carModelDTO.ModelDescription + " ya existe en el sistema");
                return(false);
            }
            else
            {
                cmd.Connection  = conexion.AbrirConexion();
                cmd.CommandText = "insert into car_model values (@CarModelDes, @CarBrandId, @CarBrand, @status)";
                cmd.CommandType = CommandType.Text;

                FillCarModelDtoParams(carModelDTO);

                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();
                conexion.CerrarConexion();

                return(true);
            }
        }
Example #16
0
 public void DelteCarModel(CarModelDTO item)
 {
     Db.CarModels.Delete(item.Id);
     Db.Save();
 }
 public async Task <CarModelDTO> UpdateCarModelAsync(CarModelDTO data)
 {
     return(await carModelRepository.UpdateCarModelAsync(data));
 }