static void Main(string[] args) { Car car = new Car("Azul", 2022, 4.0, 2, 2); Motocycle motocycle = new Motocycle("Branca", 2021, 600); Console.ReadLine(); }
static void Main(string[] args) { //ISP - Principio da Segregação de Interface //Primeiro é importante identificar dentro das nossas interfaces //quais são aquelas que estão "infladas", muitos metodos declarados e códigos que dependem dessas interfaces //Os clientes não devem ser forçados a depender de métodos que eles não utilizam Car car = new Car("Azul", 2022, 4.0, 2, 2); Motocycle motocycle = new Motocycle("Branca", 2021, 600); Console.ReadLine(); }
public IActionResult Update(Motocycle motocycle) { var existsModel = MotocycleStore.Data.FirstOrDefault(x => x.Id == motocycle.Id); if (existsModel == null) { return(NotFound(new { errorText = $"Motocycle with id {motocycle.Id} not found" })); } MotocycleStore.Data.Remove(existsModel); MotocycleStore.Data.Add(motocycle); return(Ok(motocycle)); }
public async Task <bool> AddMotocycle(MotocycleAnnounceModel announce) { try { MotocycleBodyType bodyType = await _dbContext.MotocycleBodyTypes.FindAsync(announce.MotocycleBodyTypeId); MotocycleMake make = await _dbContext.MotocycleMakes.FindAsync(announce.MotocycleMakeId); DateTime addedDate = DateTime.Now; Motocycle unicodeAnnounce = await _dbContext.Motocycles.FindAsync(_dbContext.Motocycles.Max(c => c.Id)); string unicode = (Int32.Parse(unicodeAnnounce.AnnounceUniqueCode) + 1).ToString(); Motocycle motocycle = new Motocycle(bodyType, make, announce.MotocycleYear) { AnnounceAddedDate = addedDate, AnnounceTypeId = announce.AnnounceTypeId, Price = announce.Price, CityId = announce.CityId, Description = announce.Description, PersonTypeId = announce.PersonTypeId, Email = announce.Email, PhoneNumber = announce.PhoneNumber, Condition = announce.MotocycleCondition, MotocycleBodyTypeId = announce.MotocycleBodyTypeId, MotocycleKilometer = announce.MotocycleKilometer, MotocycleModel = announce.MotocycleModel, AnnounceUniqueCode = unicode, MotocycleMotor = announce.MotocycleMotor, }; await _dbContext.Motocycles.AddAsync(motocycle); //car files upload start AddDataPhoto(announce.Paths, motocycle.Id, "lib/images/transport/motocycle", FindTable.Motocycle); //car files upload end await _dbContext.SaveChangesAsync(); } catch (Exception exp) { throw exp; } return(true); }
static void Main(string[] args) { //Outra forma de trabalhar com OCP é o uso de interface //TypeVehicle type = TypeVehicle.CAR; TypeVehicle type = TypeVehicle.MOTORCYCLE; if (type == TypeVehicle.CAR) { Car vehicle = new Car("Azul", 2022, 2.0, 5, 4); } else { Motocycle vehicle = new Motocycle("Branco", 2021, 250); } Console.ReadLine(); }
static void Main(string[] args) { //Vamos aplicar o conceito da herança; //Por exemplo, a moto não tem porta e/ou quantidade de assentos, vamos tratar isso. TypeVehicle type = TypeVehicle.CAR; //TypeVehicle type = TypeVehicle.MOTORCYCLE; if (type == TypeVehicle.CAR) { Car vehicle = new Car("Azul", 2022, 2.0, 5, 4); } else { Motocycle vehicle = new Motocycle("Branco", 2021, 250); } Console.ReadLine(); }