예제 #1
0
        public async Task <IHttpActionResult> GetStation(int id)
        {
            IStationDao   stationDao  = AdoFactory.Instance.GetStationDao("wetr");
            IAddressDao   addressDao  = AdoFactory.Instance.GetAddressDao("wetr");
            ICommunityDao communitDao = AdoFactory.Instance.GetCommunityDao("wetr");
            IDistrictDao  districtDao = AdoFactory.Instance.GetDistrictDao("wetr");
            IProvinceDao  provinceDao = AdoFactory.Instance.GetProvinceDao("wetr");
            ICountryDao   countryDao  = AdoFactory.Instance.GetCountryDao("wetr");

            Station myStations = await stationDao.FindByIdAsync(id);

            if (myStations == null)
            {
                return(Content(HttpStatusCode.BadRequest, new object()));
            }

            StationDTO station = new StationDTO(myStations);

            station.CommunityId = (await addressDao.FindByIdAsync(station.AddressId)).CommunityId;
            station.DistrictId  = (await communitDao.FindByIdAsync(station.CommunityId)).DistrictId;
            station.ProvinceId  = (await districtDao.FindByIdAsync(station.DistrictId)).ProvinceId;
            station.CountryId   = (await provinceDao.FindByIdAsync(station.ProvinceId)).CountryId;
            station.Location    = (await addressDao.FindByIdAsync(station.AddressId)).Location;

            return(Content(HttpStatusCode.OK, station));
        }
예제 #2
0
 public RepositoryUser(IConnectionFactory connectionFactory) : base(connectionFactory)
 {
     _roleDao    = DaoFactory.CreateRoleDao();
     _userDao    = DaoFactory.CreateUserDao();
     _addressDao = DaoFactory.CreateAddressDao();
     _cityDao    = DaoFactory.CreateCityDao();
 }
예제 #3
0
 public AddressHistoryService(IAddressDao dao, ICommandBus commandBus, IAccountDao accountDao, IOrderDao orderDao)
 {
     _dao        = dao;
     _commandBus = commandBus;
     _accountDao = accountDao;
     _orderDao   = orderDao;
 }
예제 #4
0
        public async Task <IHttpActionResult> GetMyStations()
        {
            string token  = Request.Headers.GetValues("Authorization").FirstOrDefault();
            int    userId = JwtHelper.Instance.GetUserId(token);

            IStationDao   stationDao  = AdoFactory.Instance.GetStationDao("wetr");
            IAddressDao   addressDao  = AdoFactory.Instance.GetAddressDao("wetr");
            ICommunityDao communitDao = AdoFactory.Instance.GetCommunityDao("wetr");
            IDistrictDao  districtDao = AdoFactory.Instance.GetDistrictDao("wetr");
            IProvinceDao  provinceDao = AdoFactory.Instance.GetProvinceDao("wetr");
            ICountryDao   countryDao  = AdoFactory.Instance.GetCountryDao("wetr");

            IEnumerable <Station> myStations = null;

            myStations = await stationDao.FindByUserIdAsync(userId);

            List <StationDTO> convertedStations = new List <StationDTO>();

            /* Infer location ids for convenience */
            foreach (var s in myStations)
            {
                StationDTO station = new StationDTO(s);

                station.CommunityId = (await addressDao.FindByIdAsync(station.AddressId)).CommunityId;
                station.DistrictId  = (await communitDao.FindByIdAsync(station.CommunityId)).DistrictId;
                station.ProvinceId  = (await districtDao.FindByIdAsync(station.DistrictId)).ProvinceId;
                station.CountryId   = (await provinceDao.FindByIdAsync(station.ProvinceId)).CountryId;
                station.Location    = (await addressDao.FindByIdAsync(station.AddressId)).Location;

                convertedStations.Add(station);
            }

            return(Content(HttpStatusCode.OK, convertedStations));
        }
예제 #5
0
 public AddressManager(ICountryDao countryDao,
                       IProvinceDao provinceDao,
                       IDistrictDao districtDao,
                       ICommunityDao communityDao,
                       IAddressDao addressDao
                       )
 {
     this.countryDao   = countryDao;
     this.communityDao = communityDao;
     this.provinceDao  = provinceDao;
     this.districtDao  = districtDao;
     this.addressDao   = addressDao;
 }
예제 #6
0
        public async Task <IHttpActionResult> EditStationAsync(StationDTO station)
        {
            /* Check if model is valid */
            if (!ModelState.IsValid)
            {
                var errors = ModelState.ToDictionary(
                    kvp => kvp.Key,
                    kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
                    );
                return(Content(HttpStatusCode.BadRequest, errors));
            }
            string token  = Request.Headers.GetValues("Authorization").FirstOrDefault();
            int    userId = JwtHelper.Instance.GetUserId(token);

            IStationDao stationDao    = AdoFactory.Instance.GetStationDao("wetr");
            Station     stationToEdit = await stationDao.FindByIdAsync(station.StationId);

            /* If the station doesn't belong to the user */
            if (stationToEdit.UserId != userId)
            {
                return(Content(HttpStatusCode.Forbidden, new object()));
            }

            /* Create new address */
            IAddressDao addressDao = AdoFactory.Instance.GetAddressDao("wetr");

            await addressDao.UpdateAsync(new Address()
            {
                AddressId   = stationToEdit.AddressId,
                CommunityId = station.CommunityId,
                Location    = station.Location,
                Zip         = "NO_ZIP"
            });

            int newAddressId = Convert.ToInt32((await addressDao.GetNextId()) - 1);

            station.AddressId = newAddressId;


            /* Edit Station */
            await stationDao.UpdateAsync(station.ToStation());

            return(Content(HttpStatusCode.OK, new object()));
        }
예제 #7
0
        public async Task <IHttpActionResult> CreateStation(StationDTO station)
        {
            /* Check if model is valid */
            if (!ModelState.IsValid)
            {
                var errors = ModelState.ToDictionary(
                    kvp => kvp.Key,
                    kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray()
                    );
                return(Content(HttpStatusCode.BadRequest, errors));
            }

            string token  = Request.Headers.GetValues("Authorization").FirstOrDefault();
            int    userId = JwtHelper.Instance.GetUserId(token);

            IStationDao stationDao = AdoFactory.Instance.GetStationDao("wetr");
            IAddressDao addressDao = AdoFactory.Instance.GetAddressDao("wetr");



            await addressDao.InsertAsync(new Address()
            {
                CommunityId = station.CommunityId,
                Location    = station.Location,
                Zip         = "NO_ZIP"
            });

            int newAddressId = Convert.ToInt32((await addressDao.GetNextId()) - 1);

            /* Cleanup */
            station.AddressId = newAddressId;
            station.StationId = 0;
            station.UserId    = userId;

            await stationDao.InsertAsync(station.ToStation());

            return(Content(HttpStatusCode.OK, new object()));
        }
예제 #8
0
        public async Task <IHttpActionResult> GetStations(int communityId)
        {
            IStationDao   stationDao  = AdoFactory.Instance.GetStationDao("wetr");
            IAddressDao   addressDao  = AdoFactory.Instance.GetAddressDao("wetr");
            ICommunityDao communitDao = AdoFactory.Instance.GetCommunityDao("wetr");
            IDistrictDao  districtDao = AdoFactory.Instance.GetDistrictDao("wetr");
            IProvinceDao  provinceDao = AdoFactory.Instance.GetProvinceDao("wetr");
            ICountryDao   countryDao  = AdoFactory.Instance.GetCountryDao("wetr");

            IEnumerable <Station> stations = null;

            stations = await stationDao.FindAllAsync();

            List <StationDTO> convertedStations = new List <StationDTO>();

            /* Infer location ids for convenience */
            foreach (var s in stations)
            {
                StationDTO station = new StationDTO(s);

                station.CommunityId = (await addressDao.FindByIdAsync(station.AddressId)).CommunityId;
                station.DistrictId  = (await communitDao.FindByIdAsync(station.CommunityId)).DistrictId;
                station.ProvinceId  = (await districtDao.FindByIdAsync(station.DistrictId)).ProvinceId;
                station.CountryId   = (await provinceDao.FindByIdAsync(station.ProvinceId)).CountryId;
                station.Location    = (await addressDao.FindByIdAsync(station.AddressId)).Location;

                convertedStations.Add(station);
            }

            if (communityId != 0)
            {
                convertedStations.RemoveAll(s => s.CommunityId != communityId);
            }

            return(Content(HttpStatusCode.OK, convertedStations));
        }
예제 #9
0
 public AddressBaseMgr(IAddressDao entityDao)
 {
     this.entityDao = entityDao;
 }
예제 #10
0
 public AddressLogic(IAddressDao <Address> iAddressDao, IValidateLogic <Address> IValidateLogic)
 {
     addressDao    = iAddressDao ?? throw new ArgumentNullException($"{nameof(iAddressDao)} is null!");
     validateLogic = IValidateLogic ?? throw new ArgumentNullException($"{nameof(IValidateLogic)} is null!");
 }
예제 #11
0
 public AddressLogic(IAddressDao addressDao)
 {
     this._addressDao = addressDao;
 }
예제 #12
0
 public AddressMgr(IAddressDao entityDao, ICriteriaMgr criteriaMgr)
     : base(entityDao)
 {
     this.criteriaMgr = criteriaMgr;
 }
 public AddressesService(IAddressDao dao)
 {
     Dao = dao;
 }
예제 #14
0
 public AddressController(IAddressDao addressDao)
 {
     _addressDao = addressDao;
 }
예제 #15
0
 public AddressBaseMgr(IAddressDao entityDao)
 {
     this.entityDao = entityDao;
 }
예제 #16
0
 static Dependencies()
 {
     addressDao           = new AddressDaoDb();
     addressValidateLogic = new AddressValidateLogic();
     AddressLogic         = new AddressLogic(addressDao, addressValidateLogic);
 }
예제 #17
0
 public AddressMgr(IAddressDao entityDao, ICriteriaMgr criteriaMgr)
     : base(entityDao)
 {
     this.criteriaMgr = criteriaMgr;
 }
예제 #18
0
 public LocationManager(ILocationDao locationDao, IAddressDao addressDao)
 {
     _locationDao = locationDao;
     _addressDao  = addressDao;
 }
예제 #19
0
 public AddressManager(IAddressDao addressDao)
 {
     _addressDao = addressDao;
 }