public ActionResult Edit(BusStationModel model)
        {
            ViewBag.IsInsert = false;
            // does existing bus station
            var result = _busStationService.GetList().Where(o => o.IdBusStation != model.IdBusStation && o.Name == model.Name);

            if (result.Count() == 0) // not existing, can insert
            {
                var    entity = _mapper.Map <BusStation>(model);
                string error  = _busStationService.Update(entity);
                if (error != null)
                {
                    ModelState.AddModelError(string.Empty, error);
                    return(View("InsertOrUpdate", model));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, string.Format(Resource.ExistingNameOfError, Resource.BusStation));
                return(View("InsertOrUpdate", model));
            }
        }
Esempio n. 2
0
        public async Task <BusStationModel> UpdateAsync(BusStationModel model)
        {
            var entity = MapFromModel(model);
            var result = await _busStationRepository.UpdateAsync(entity);

            return(MapToModel <BusStationModel>(result));
        }
        public async Task UpdateAsync_WhenCalled_InvokesRepositoryUpdateMethod()
        {
            // Arrange
            var busStation = new BusStationModel();

            // Act
            await _busStationService.UpdateAsync(busStation);

            // Assert
            _mockAsyncRepository.Verify(m => m.UpdateAsync(It.IsAny <MasterBusStation>()), Times.Once);
        }
Esempio n. 4
0
        public async Task UpdateAsync(BusStationModel model)
        {
            var busStation = await _repository.GetByIdAsync(model.BusStationId);

            busStation.RouteId        = model.RouteId;
            busStation.BusStationName = model.BusStationName;
            busStation.BusStationCode = model.BusStationCode;
            busStation.TimeInDay      = model.TimeInDay;
            busStation.TimeInNight    = model.TimeInNight;

            await _repository.UpdateAsync(busStation);
        }
Esempio n. 5
0
        public async Task AddAsync(BusStationModel model)
        {
            var busStation = new MasterBusStation
            {
                RouteId        = model.RouteId,
                BusStationName = model.BusStationName,
                BusStationCode = model.BusStationCode,
                TimeInDay      = model.TimeInDay,
                TimeInNight    = model.TimeInNight,
            };

            await _repository.AddAsync(busStation);
        }
Esempio n. 6
0
        private async void Find()
        {
            string uri      = "http://openapi.aibang.com/bus/stats?alt=json&app_key=" + App.AiBangApi + "&city=" + App.City + "&q=" + Station;
            string response = await HttpGet.Get(uri);

            try
            {
                DataContractJsonSerializer ds = new DataContractJsonSerializer(typeof(BusStationModel));
                MemoryStream    ms            = new MemoryStream(Encoding.UTF8.GetBytes(response));
                BusStationModel stationDemo   = ds.ReadObject(ms) as BusStationModel;
                StationList = stationDemo.stats.stat;
            }
            catch (InvalidCastException ex)
            {
                Msg("亲,您输入站点名称有误.");
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Create(BusStationEditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var busStation = new BusStationModel
            {
                RouteId        = viewModel.RouteId,
                BusStationName = viewModel.BusStationName,
                BusStationCode = viewModel.BusStationCode,
                TimeInDay      = viewModel.TimeInDay,
                TimeInNight    = viewModel.TimeInNight
            };

            await _busStationService.AddAsync(busStation);

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 8
0
        public async Task <IActionResult> Edit(BusStationEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var editModel = new BusStationModel
            {
                BusStationId   = model.BusStationId,
                RouteId        = model.RouteId,
                BusStationName = model.BusStationName,
                BusStationCode = model.BusStationCode,
                TimeInDay      = model.TimeInDay,
                TimeInNight    = model.TimeInNight
            };

            await _busStationService.UpdateAsync(editModel);

            return(RedirectToAction(nameof(Index)));
        }
 public ActionResult Create(BusStationModel model)
 {
     ViewBag.IsInsert = true;
     // does existing bus station
     if (_busStationService.GetList().Where(o => o.Name.ToLower() == model.Name.Trim().ToLower()).Count() == 0) // not existing, can insert
     {
         var    entity = _mapper.Map <BusStation>(model);
         string error  = _busStationService.Insert(entity);
         if (error != null)
         {
             ModelState.AddModelError(null, error);
             return(View("InsertOrUpdate", model));
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         ModelState.AddModelError(string.Empty, string.Format(Resource.ExistingNameOfError, Resource.BusStation));
         return(View("InsertOrUpdate", model));
     }
 }
Esempio n. 10
0
        public async Task <BusStationModel> Put(int id, [FromBody] BusStationModel model)
        {
            var result = await _busStationService.UpdateAsync(model);

            return(result);
        }
Esempio n. 11
0
        public async Task <BusStationModel> Post([FromBody] BusStationModel model)
        {
            var result = await _busStationService.AddAsync(model);

            return(result);
        }