Ejemplo n.º 1
0
 public AccountSimpleDTO Login(string username, string password)
 {
     using (var uow = new UnitOfWork())
     {
         var accountRepository = uow.GetRepository <Account>();
         var account           = accountRepository.FindBy(e => e.UserName == username && e.UserPassword == password);
         var res = account.FirstOrDefault();
         if (res != null)
         {
             AccountSimpleMapper accounMapper = new AccountSimpleMapper();
             return(accounMapper.MapToDTO(res));
         }
         return(null);
     }
 }
        public AccountSimpleDTO addAccount(SignUpAccountDTO accountVM)
        {
            using (var uow = new UnitOfWork())
            {
                var           accountRepository = uow.GetRepository <Account>();
                var           adressRepository  = uow.GetRepository <Adress>();
                AdressService addressService    = new AdressService();

                SignUpAccountMapper accountMaper = new SignUpAccountMapper();
                Account             account      = accountMaper.MapFromDTO(accountVM);

                var queryAccounts = accountRepository.FindBy(ac => ac.UserName == accountVM.UserName | ac.Email == accountVM.Email);
                var existAc       = queryAccounts.FirstOrDefault();

                if (existAc == null)
                {
                    var queryAddress = adressRepository.FindBy(ad => ad.latitude == accountVM.Adress.latitude &
                                                               ad.longitude == accountVM.Adress.longitude);
                    var existAd = queryAddress.FirstOrDefault();

                    if (existAd != null)
                    {
                        account.Adress = existAd;
                    }
                }
                else
                {
                    return(null);
                }

                accountRepository.Add(account);
                uow.SaveChanges();

                AccountSimpleMapper simpleAccountMapper = new AccountSimpleMapper();
                return(simpleAccountMapper.MapToDTO(account));
            }
        }