Пример #1
0
        public KlantDTO CreateKlant(string klantId)
        {
            var klant = _repositoryKlant.GetKlantByID(klantId);

            if (klant != null)
            {
                return(null);
            }
            var newKlant     = _klantMapper.MapToModel(klantId);
            var createdKlant = _repositoryKlant.CreateKlant(newKlant);

            try
            {
                _repositoryKlant.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(null);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(_klantMapper.MapToDTO(createdKlant));
        }
Пример #2
0
        private Klant CheckIfKlantExists(string userId)
        {
            bool newKlant = false;
            var  klant    = _repositoryKlant.GetKlantByID(userId);

            if (klant == null)
            {
                klant = _repositoryKlant.CreateKlant(new Klant()
                {
                    AzureId      = userId,
                    Winkelwagens = new List <Winkelwagen>()
                });
                newKlant = true;
            }
            try
            {
                if (newKlant)
                {
                    _repositoryKlant.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(klant);
        }
Пример #3
0
        public KlantDTO MakeAdminKlant(string adminId)
        {
            var admin = _repositoryAdmin.GetAdminByID(adminId);

            if (admin == null)
            {
                return(null);
            }
            _repositoryAdmin.DeleteAdmin(adminId);

            var klant = _repositoryKlant.GetKlantByID(adminId);

            if (klant != null)
            {
                return(null);
            }
            var newKlant     = _klantMapper.MapToModel(adminId);
            var createdKlant = _repositoryKlant.CreateKlant(newKlant);

            try
            {
                _repositoryKlant.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(null);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            return(_klantMapper.MapToDTO(createdKlant));
        }
Пример #4
0
        public BestellingDTO AddBestellingToCustomer(string custId)
        {
            var bestelling = new BestellingCreateUpdateDTO
            {
                Producten = new List <BestellingItem>(),
                Datum     = DateTime.Now,
                Klant     = _klantRepository.GetKlantByID(custId)
            };
            var winkelwagenGebruiker = _repositoryWinkelwagen.GetWinkelwagenByKlantId(custId);

            foreach (VerkoopItem item in winkelwagenGebruiker.Producten)
            {
                bestelling.Producten.Add(new BestellingItem()
                {
                    Aantal = item.Aantal, Product = item.Product
                });
            }
            bestelling.TotaalPrijs = _costCalculator.CalculateCost(winkelwagenGebruiker);
            var newBestelling     = _bestellingMapper.MapToModel(bestelling);
            var createdBestelling = _repositoryBestelling.AddBestellingToCustomer(newBestelling);

            winkelwagenGebruiker.TotaalPrijs = 0.0;
            winkelwagenGebruiker.Producten   = new List <WinkelwagenItem>();

            try
            {
                _repositoryBestelling.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(null);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(_bestellingMapper.MapToDTO(createdBestelling));
        }