Ejemplo n.º 1
0
 public void Update(CarWorkshop model)
 {
     if (!_carWorkshopContext.Workshops.ContainsKey(model.CompanyName))
     {
         _carWorkshopContext.Workshops[model.CompanyName] = model;
     }
 }
Ejemplo n.º 2
0
        public async Task<Notifiable> Handle(UpdateCarWorkshopCommand request, CancellationToken cancellationToken)
        {
            var notifiable = new Notifiable();
            var existsCity = await _repository.ValidateCityById(request.CityId);

            if (!existsCity)
                notifiable.AddError($"A cidade não está cadastrada");

            var exists = await _repository.Exists(x => x.Id == request.Id);

            if (!exists)
                notifiable.AddError($"A oficina {request.Name} não está cadastrada");

            if (!notifiable.HasErrors)
            {
                var updated = new CarWorkshop(request.Id, request.Name, request.Phone, request.Address, request.CityId);

                _repository.Update(updated);
                await _repository.Save();
                updated = await _repository.GetById(updated.Id);
                notifiable.SetData(updated);
                notifiable.SetMessage("");
            }

            return notifiable;
        }
Ejemplo n.º 3
0
    static void Main(string[] args)
    {
        var     carWorkshop = new CarWorkshop();
        dynamic whell       = new Wheel();
        dynamic chassis     = new Chassis();
        dynamic engine      = new Engine();

        Console.WriteLine(carWorkshop.Repair(whell));
        Console.WriteLine(carWorkshop.Repair(chassis));
        Console.WriteLine(carWorkshop.Repair(engine));
        Console.ReadLine();
    }
Ejemplo n.º 4
0
        public static dynamic AsCustomerView(this CarWorkshop workshop)
        {
            var staticStorageBox = StaticStorageBox.GetInstance();

            return(workshop == null ? null : new
            {
                CompanyName = workshop.Name,
                Trademarks = workshop.Trademarks.Select(t => staticStorageBox.Trademarks.First(t1 => t1.Id == t)),
                City = staticStorageBox.Cities.First(c => c.Id == workshop.City_Id),
                PostalCode = workshop.PostalCode,
                Country = staticStorageBox.Countries.First(c => c.Id == workshop.Country_Id)
            });
        }
Ejemplo n.º 5
0
        public StatusDto Add(CarWorkshop model)
        {
            if (!_carWorkshopContext.Workshops.ContainsKey(model.CompanyName))
            {
                _carWorkshopContext.Workshops.Add(model.CompanyName, model);

                return(new StatusDto {
                    Message = "User successfully added", Status = ActionResult.Success
                });
            }

            return(new StatusDto {
                Message = "Username already exist", Status = ActionResult.UniqueKeyError
            });
        }
        public async Task <Notifiable> Handle(CreateCarWorkshopCommand request, CancellationToken cancellationToken)
        {
            var existsCity = await _repository.ValidateCityById(request.CityId);

            if (!existsCity)
            {
                return(new Notifiable(new NotifiableError($"A Cidade {request.Name} não está cadastrada")));
            }

            var carWorkshop = new CarWorkshop(request.Name, request.Phone, request.Address, request.CityId);

            await _repository.Add(carWorkshop);

            await _repository.Save();

            carWorkshop = await _repository.GetById(carWorkshop.Id);

            return(new Notifiable("Oficina cadastrada com sucesso", carWorkshop));
        }
Ejemplo n.º 7
0
 public void DeleteWorkshop(CarWorkshop model)
 {
     _carWorkshopRepository.Delete(model);
 }
Ejemplo n.º 8
0
 public StatusDto AddWorkshop(CarWorkshop model)
 {
     return(_carWorkshopRepository.Add(model));
 }
Ejemplo n.º 9
0
 public void Delete(CarWorkshop model)
 {
     _carWorkshopContext.Workshops.Remove(model.CompanyName);
 }
Ejemplo n.º 10
0
 public void Post([FromBody] CarWorkshop value)
 {
     carWorkshopService.Add(value);
 }