Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        private bool IsMakeExist(int id)
        {
            VehicleMake vehicleMake = Context.VehicleMakes.Find(id);

            if (vehicleMake == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
 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);
     }
 }
Пример #7
0
        public async Task <VehicleMakeRepo> GetById(int id)
        {
            VehicleMake vehicleMake = await vehiclesSet.FindAsync(id);

            return(mapper.Map <VehicleMakeRepo>(vehicleMake));
        }