Пример #1
0
 public void BindFromUIModel(AdressModel model)
 {
     using (RepositoryHolder scope = new RepositoryHolder())
     {
         AdressMapper mapper = new AdressMapper();
         var dbModel = mapper.ModelToEntity(model);
         scope.AdressRepository.Insert(dbModel);
         scope.SaveChanges();
     }
 }
Пример #2
0
        public List<AdressModel> BindFromEntitiesBy(int id)
        {

            using (RepositoryHolder scope = new RepositoryHolder())
            {
                AdressMapper mapper = new AdressMapper();
                //CurrencyRateMapper mapper2 = new CurrencyRateMapper();   
                List<AdressModel> result = mapper.EntityToModel(
                    scope.AdressRepository
                    .FetchBy(p => p.cIdBank == id)
                   .ToList());
                return result;
            }

        }
Пример #3
0
        public SportEventDetailDTO editSportEvent(SportEventDetailDTO sportEventVM)
        {
            using (var uow = new UnitOfWork())
            {
                var accountRepository    = uow.GetRepository <Account>();
                var addressRepository    = uow.GetRepository <Adress>();
                var sportRepository      = uow.GetRepository <Sport>();
                var sportEventRepository = uow.GetRepository <SportEvent>();

                SportEventDetailMapper sportEventMapper = new SportEventDetailMapper();
                SportEvent             sportEvent       = sportEventMapper.MapFromDTO(sportEventVM);

                AdressMapper addressMapper = new AdressMapper();
                var          queryaddress  = addressRepository.FindBy(ad => ad.latitude == sportEventVM.Adress.latitude & ad.longitude == sportEventVM.Adress.longitude);
                Adress       address       = queryaddress.FirstOrDefault();


                if (address == null)
                {
                    addressRepository.Add(addressMapper.MapFromDTO(sportEventVM.Adress));
                    uow.SaveChanges();
                }
                address                   = addressRepository.FindBy(ad => ad.latitude == sportEventVM.Adress.latitude & ad.longitude == sportEventVM.Adress.longitude).FirstOrDefault();
                sportEvent.AdressId       = address.Id;
                sportEvent.Adress         = address;
                sportEvent.OwnerId        = sportEventVM.Owner.Id;
                sportEvent.Owner.AdressId = sportEvent.Owner.Adress.Id;

                SportMapper sportMapper = new SportMapper();
                var         querysport  = sportRepository.FindBy(sp => sp.Name == sportEventVM.Category.Name);
                Sport       sport       = querysport.FirstOrDefault();


                if (sport == null)
                {
                    sportRepository.Add(sportMapper.MapFromDTO(sportEventVM.Category));
                    uow.SaveChanges();
                }
                sport = sportRepository.FindBy(sp => sp.Name == sportEventVM.Category.Name).FirstOrDefault();
                sportEvent.Category   = sport;
                sportEvent.CategoryId = sport.Id;
                sportEventRepository.Edit(sportEvent);
                uow.SaveChanges();
                return(sportEventMapper.MapToDTO(sportEvent));
            }
        }
Пример #4
0
        public AdressDTO getAdressById(int id)
        {
            using (var uow = new UnitOfWork())
            {
                var    adressRepository = uow.GetRepository <Adress>();
                Adress adress           = adressRepository.GetById(id);

                if (adress == null)
                {
                    return(null);
                }

                AdressMapper adressMapper = new AdressMapper();
                AdressDTO    adressVM     = adressMapper.MapToDTO(adress);
                return(adressVM);
            }
        }
Пример #5
0
        public List<AdressModel> BindFromEntities()
        {
            using (RepositoryHolder scope = new RepositoryHolder())
            {
                AdressMapper mapper = new AdressMapper();
                
                List<AdressModel> result =  //mapper.EntityToModel(
                    scope.AdressRepository
                    .Fetch()
                    .Select
                        (
                            p => 
                                mapper.EntityToModel(p)
                        )
                   .ToList();
                return result;
            }

        }
        public SignUpAccountDTO editAccount(SignUpAccountDTO accountVM)
        {
            using (var uow = new UnitOfWork())
            {
                var accountRepository = uow.GetRepository <Account>();
                var addressRepository = uow.GetRepository <Adress>();

                var accUser  = accountRepository.FindBy(ac => ac.UserName == accountVM.UserName);
                var accEmail = accountRepository.FindBy(ac => ac.Email == accountVM.Email);

                if ((accUser.Count() == 1 && accUser.FirstOrDefault().Id != accountVM.Id) | (accEmail.Count() == 1 && accEmail.FirstOrDefault().Id != accountVM.Id))
                {
                    return(null);
                }


                AdressMapper addressMapper = new AdressMapper();
                var          queryaddress  = addressRepository.FindBy(ad => ad.latitude == accountVM.Adress.latitude & ad.longitude == accountVM.Adress.longitude);
                Adress       address       = queryaddress.FirstOrDefault();



                Account account = accountRepository.GetById(accountVM.Id);
                if (address == null)
                {
                    addressRepository.Add(addressMapper.MapFromDTO(accountVM.Adress));
                    uow.SaveChanges();
                }

                address              = addressRepository.FindBy(ad => ad.latitude == accountVM.Adress.latitude & ad.longitude == accountVM.Adress.longitude).FirstOrDefault();
                account.AdressId     = address.Id;
                account.Adress       = address;
                account.LastName     = accountVM.LastName;
                account.FirstName    = accountVM.FirstName;
                account.Email        = accountVM.Email;
                account.UserName     = accountVM.UserName;
                account.UserPassword = accountVM.Password;
                accountRepository.Edit(account);
                uow.SaveChanges();
                return(accountVM);
            }
        }
Пример #7
0
        public AdressDTO deleteAdress(int id)
        {
            using (var uow = new UnitOfWork())
            {
                var adressRepository = uow.GetRepository <Adress>();
                var adress           = adressRepository.GetById(id);

                if (adress == null)
                {
                    return(null);
                }
                else
                {
                    adressRepository.Delete(id);
                    uow.SaveChanges();

                    AdressMapper adressMapper = new AdressMapper();
                    AdressDTO    adressVM     = adressMapper.MapToDTO(adress);
                    return(adressVM);
                }
            }
        }
Пример #8
0
        public AdressDTO addAdress(AdressDTO adressVM)
        {
            using (var uow = new UnitOfWork())
            {
                var adressRepository = uow.GetRepository <Adress>();

                var query   = adressRepository.FindBy(ad => ad.latitude == adressVM.latitude && ad.longitude == adressVM.longitude);
                var existAd = query.FirstOrDefault();

                if (existAd == null)
                {
                    AdressMapper adressMapper = new AdressMapper();
                    Adress       adress       = adressMapper.MapFromDTO(adressVM);
                    adressRepository.Add(adress);
                    uow.SaveChanges();
                    return(adressVM);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #9
0
        public List<AdressModel> BindFromEntities(string city, string country)
        {
            using (RepositoryHolder scope = new RepositoryHolder())
            {
                AdressMapper mapper = new AdressMapper();

                List<AdressModel> result = mapper.EntityToModel(
                    scope.AdressRepository
                    .FetchBy(p =>p.cCity==city)

                   .ToList());
                /*
                if (result == null)
                {
                    return GetData(city, country);
                }
                else
                {
                    return result;
                }*/
                return result;
            }

        }