Exemplo n.º 1
0
        public IActionResult Create([Bind] CarrierInputModel carrier)
        {
            if (!ModelState.IsValid)
            {
                TempData["msg"] = "Model is not valid!";
                return(Create());
            }
            City    newCity    = _cityService.GetByName(carrier.CityName);
            Address newAddress = new Address
            {
                StreetName   = carrier.StreetName,
                StreetNumber = carrier.StreetNumber,
                City         = newCity
            };
            Carrier newCarrier = new Carrier
            {
                Name    = carrier.Name,
                Address = newAddress
            };

            if (_carrierService.AddNewCarrier(newCarrier))
            {
                TempData["msg"] = "Carrier is created!";
            }
            else
            {
                TempData["msg"] = "Carrier is not created!";
            }

            return(RedirectToPage("~/Home"));
        }
Exemplo n.º 2
0
        public IActionResult Edit(int id)
        {
            Carrier carrier = _carrierService.GetById(id);

            CarrierInputModel carrierInput = new CarrierInputModel
            {
                Name         = carrier.Name,
                StreetName   = carrier.Address.StreetName,
                StreetNumber = carrier.Address.StreetNumber,
                Cities       = _cityService.GetAll(),
                CityName     = carrier.Address.City.Name
            };

            return(View(carrierInput));
        }
Exemplo n.º 3
0
        public IActionResult Create()
        {
            var cities = _cityService.GetAll();

            var allCities = cities.Select(c => new City
            {
                Id   = c.Id,
                Name = c.Name
            });

            var model = new CarrierInputModel
            {
                Cities = allCities
            };

            return(View(model));
        }
Exemplo n.º 4
0
 private void Update(Guid id, CarrierInputModel model)
 {
     Service.Update(id, model).Wait();
 }
Exemplo n.º 5
0
 private void Add(CarrierInputModel model)
 {
     Service.Add(model).Wait();
 }
Exemplo n.º 6
0
        public async Task <IActionResult> Update(Guid id, CarrierInputModel model)
        {
            await _service.Update(id, model);

            return(Ok());
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Add(CarrierInputModel model)
        {
            await _service.Add(model);

            return(Ok());
        }