public async Task <bool> Update(VehicleMakeRepo entity) { bool provjera = false; if (entity != null) { VehicleMake vehicleMake = mapper.Map <VehicleMake>(entity); var updatedVehicleMake = await vehiclesSet.FindAsync(entity.Id); if (updatedVehicleMake != null) { if (IsNameNotExist(updatedVehicleMake.Id, vehicleMake.Name)) { updatedVehicleMake.Name = vehicleMake.Name; provjera = true; } if (IsAbrvNotExist(updatedVehicleMake.Id, vehicleMake.Abrv)) { updatedVehicleMake.Abrv = vehicleMake.Abrv; provjera = true; } } } return(provjera); }
public async Task <IEnumerable <VehicleModelRepo> > GetVehicleModels(int id) { VehicleMake vehicleMakes = await vehiclesSet.FindAsync(id); List <VehicleModelRepo> vehicleModelsRepo = new List <VehicleModelRepo>(); vehicleModelsRepo = mapper.Map <ICollection <VehicleModel>, List <VehicleModelRepo> >(vehicleMakes.VehicleModels); return(vehicleModelsRepo); }
private bool IsMakeExist(int id) { VehicleMake vehicleMake = Context.VehicleMakes.Find(id); if (vehicleMake == null) { return(false); } else { return(true); } }
public async Task <bool> Delete(VehicleMakeRepo entity) { bool provjera = false; if (entity != null) { VehicleMake vehicleMake = mapper.Map <VehicleMake>(entity); VehicleMake make = await vehiclesSet.FindAsync(vehicleMake.Id); if (make != null && make.VehicleModels.Count == 0) { vehiclesSet.Remove(make); provjera = true; } } return(provjera); }
public async Task <bool> Add(VehicleMakeRepo entity) { bool provjera = false; if (entity != null) { VehicleMake vehicleMake = mapper.Map <VehicleMake>(entity); if (IsNotExist(vehicleMake)) { vehicleMake.VehicleModels.Clear(); VehicleMake make = vehiclesSet.Add(vehicleMake); if (make != null) { provjera = true; } } } return(provjera); }
private bool IsNotExist(VehicleMake vehicleMake) { if (!String.IsNullOrWhiteSpace(vehicleMake.Name) && !String.IsNullOrWhiteSpace(vehicleMake.Abrv)) { string name = vehicleMake.Name.ToLower(); string abrv = vehicleMake.Abrv.ToLower(); List <VehicleMake> vehicleMakes = vehiclesSet.Where(x => x.Abrv.ToLower().Equals(abrv) || x.Name.ToLower().Equals(name)).ToList(); if (vehicleMakes.Count == 0) { return(true); } else { return(false); } } else { return(false); } }
public async Task <VehicleMakeRepo> GetById(int id) { VehicleMake vehicleMake = await vehiclesSet.FindAsync(id); return(mapper.Map <VehicleMakeRepo>(vehicleMake)); }