コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Nom_Cli,Adresse,Num_Quartier")] SaveClientModel clientView)
        {
            var validator        = new SaveClientModelValidator();
            var validationResult = await validator.ValidateAsync(clientView);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var adresse = await _adresseService.GetAdresseByText(clientView.Adresse);

            if (adresse == null)
            {
                var addressToCreate = new Adresses {
                    Num_Quartier = clientView.Num_Quartier, Adresse = clientView.Adresse
                };
                await _adresseService.CreateAddress(addressToCreate);

                adresse = addressToCreate;
            }

            clientView.Num_Adresse = adresse.Id;
            var clientToCreate = _mapper.Map <SaveClientModel, Client>(clientView);

            await _clientService.AddClient(clientToCreate);

            return(RedirectToAction(nameof(Index)));
        }
コード例 #2
0
        public async Task <int> GetAdressIdForCustomer(string adresseLabel, int quartierId)
        {
            var adresse = await _adresseService.GetAdresseByText(adresseLabel);

            if (adresse == null || adresse.Num_Quartier != quartierId)
            {
                var addressToCreate = new Adresses {
                    Num_Quartier = quartierId, Adresse = adresseLabel
                };
                await _adresseService.CreateAddress(addressToCreate);

                adresse = addressToCreate;
            }

            return(adresse.Id);
        }