Exemplo n.º 1
0
        public async Task <(bool IsSuccess, Models.ViewModels.CarModel CarModel, string ErrorMessage)> PutCarModelAsync(Models.RequestModels.CarModelUpdateRequest carModel)
        {
            try
            {
                var entity = await dBContext.CarModels.FirstOrDefaultAsync(m => m.ID == carModel.ID);

                if (entity != null)
                {
                    entity.Name               = carModel.Name;
                    entity.MakeID             = carModel.MakeID;
                    entity.VehicleCategoryID  = carModel.VehicleCategoryID;
                    entity.RentalPricePerHour = carModel.RentalPricePerHour;
                    entity.FuelTypeID         = carModel.FuelTypeID;
                    entity.TrunkLimit         = carModel.TrunkLimit;

                    dBContext.Update(entity);
                    if (await dBContext.SaveChangesAsync() > 0)
                    {
                        var result = mapper.Map <DB.CarModel, Models.ViewModels.CarModel>(entity);
                        return(true, result, null);
                    }
                    return(false, null, "Failed to update record.");
                }
                return(false, null, "Montadora não encontrada.");
            }
            catch (Exception ex)
            {
                logger?.LogError(ex.ToString());
                return(false, null, ex.Message);
            }
        }
Exemplo n.º 2
0
        public async Task <(bool IsSuccess, Models.ViewModels.Make Make, string ErrorMessage)> PutMakeAsync(Models.RequestModels.MakeUpdateRequest make)
        {
            try
            {
                var entity = await dBContext.Makes.FirstOrDefaultAsync(m => m.ID == make.ID);

                if (entity != null)
                {
                    entity.Name = make.Name;
                    dBContext.Update(entity);
                    if (await dBContext.SaveChangesAsync() > 0)
                    {
                        var result = mapper.Map <DB.Make, Models.ViewModels.Make>(entity);
                        return(true, result, null);
                    }
                    return(false, null, "Failed to update record.");
                }
                return(false, null, "Montadora não encontrada.");
            }
            catch (Exception ex)
            {
                logger?.LogError(ex.ToString());
                return(false, null, ex.Message);
            }
        }
Exemplo n.º 3
0
        public async Task <(bool IsSuccess, Models.ViewModels.Vehicle Vehicle, string ErrorMessage)> PutVehicleAsync(VehicleUpdateRequest vehicle)
        {
            try
            {
                var entity = await dBContext.Vehicles.FirstOrDefaultAsync(v => v.ID == vehicle.ID);

                if (entity != null)
                {
                    entity.CarModelID   = vehicle.CarModelID;
                    entity.LicensePlate = string.IsNullOrEmpty(vehicle.LicensePlate) ? entity.LicensePlate : vehicle.LicensePlate;
                    entity.ModelYear    = vehicle.ModelYear;

                    dBContext.Update(entity);

                    if (await dBContext.SaveChangesAsync() > 0)
                    {
                        entity = await dBContext.Vehicles.Include(m => m.CarModel).Include(m => m.CarModel.Make).Include(m => m.CarModel.VehicleCategory).Include(c => c.CarModel.FuelType).FirstOrDefaultAsync(v => v.ID == entity.ID);

                        var result = mapper.Map <DB.Vehicle, Models.ViewModels.Vehicle>(entity);
                        return(true, result, null);
                    }
                    return(false, null, "Failed to update record.");
                }
                return(false, null, "Montadora não encontrada.");
            }
            catch (Exception ex)
            {
                logger?.LogError(ex.ToString());
                return(false, null, ex.Message);
            }
        }