public void Update(StationDTO newValue) { Name = newValue.Name; Address = newValue.Address; Longitude = newValue.Longitude; Latitude = newValue.Latitude; }
public static StationDTO InsertStation(StationDTO dto) { try { Station s = StationDTO.FromDTO(dto); s.Id = Guid.NewGuid().ToString(); var query = DataLayer.Client.Cypher .Create("(station: Station {s})") .WithParam("s", s) .Return <Station>("station") .Results; if (query != null && query.Count <Station>() > 0) { return(new StationDTO(query.ToList()[0])); } return(null); } catch (Exception e) { return(null); } }
// POST api/stations public HttpResponseMessage CreateStation([FromBody] StationDTO stationDTO) { Station newStation = new Station(); newStation.Address = stationDTO.Address; newStation.Name = stationDTO.Name; newStation.Latitude = stationDTO.Latitude; newStation.Longitude = stationDTO.Longitude; foreach (var x in unitOfWork.Lines.GetAll()) { foreach (var y in stationDTO.Lines) { if (x.Id == y.Id) { newStation.Lines.Add(x); } } } unitOfWork.Stations.Add(newStation); unitOfWork.Complete(); var message = Request.CreateResponse(HttpStatusCode.Created, newStation); message.Headers.Location = new Uri(Request.RequestUri + "/" + newStation.Id.ToString()); return(message); }
public IActionResult SearchElectoralDistrictByStation(StationDTO stationDTO) { if (stationDTO != null) { District district = _context.District.Where(d => d.StationId == stationDTO.IdStation).FirstOrDefault(); List <ElectoralDistrict> electoralDistrict = _context.ElectoralDistrict.Where(ed => ed.IdElectoralDistrict == district.ElectoralDistrictId).ToList(); if (electoralDistrict.Any()) { List <ElectoralDistrictDTO> electoralDistrictDTOs = electoralDistrict.Select(ed => new ElectoralDistrictDTO { IdElectoralDistrict = ed.IdElectoralDistrict, Name = ed.Name }).ToList(); return(Ok(electoralDistrictDTOs)); } else { return(NoContent()); } } else { return(NoContent()); } }
public void EditStation(StationDTO stationDto) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <StationDTO, Station>()).CreateMapper(); var item = mapper.Map <StationDTO, Station>(stationDto); _Database.Stations.Update(item); }
// PUT api/stations/5 public HttpResponseMessage UpdateStation(int id, [FromBody] StationDTO stationDTO) { var stationToBeUpdated = unitOfWork.Stations.GetAll().Where(x => x.Id == id && x.Deleted == false).SingleOrDefault(); stationToBeUpdated.Name = stationDTO.Name; stationToBeUpdated.Address = stationDTO.Address; stationToBeUpdated.Longitude = stationDTO.Longitude; stationToBeUpdated.Latitude = stationDTO.Latitude; List <Line> listOfLines = new List <Line>(); foreach (var x in unitOfWork.Lines.GetAll()) { foreach (var y in stationDTO.Lines) { if (x.Id == y.Id) { listOfLines.Add(x); } } } stationToBeUpdated.Lines.Clear(); stationToBeUpdated.Lines = listOfLines; if (stationToBeUpdated != null) { unitOfWork.Stations.Update(stationToBeUpdated); unitOfWork.Complete(); return(Request.CreateResponse(HttpStatusCode.OK, stationToBeUpdated)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Station with that id number doesn't exist.")); } }
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)); }
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)); }
public IResult Update(StationDTO dto) { Repo.Update(Mapper.DeMap(dto)); return(new Result() { Message = ResponseMessageType.None, ResponseStatusType = ResponseStatusType.Successed }); }
public async Task <long> Save(StationDTO entity) { try { return(await _stationDAL.Save(_mapper.Map <Station>(entity))); } catch (Exception ex) { return(0); } }
public void StationStateUpdate(StationDTO stationDTO) { if (ListsInitialized) { StationDTO st = StationsState.Where(s => s.StationID == stationDTO.StationID).FirstOrDefault(); StationsState.Remove(st); StationsState.Insert(st.StationID - 1, stationDTO); //StationsState.Add(stationDTO); UpdateStationState(); } }
private static KeyValuePair <string, string> FindResourceType <T>() { return(default(T) switch { GbfsDTO _ => new KeyValuePair <string, string>(GbfsDiscovery, "GBFS Discovery"), BikeStatusDTO _ => new KeyValuePair <string, string>("free_bike_status", "Bikes"), StationDTO _ => new KeyValuePair <string, string>("station_information", "Stations"), StationStatusDTO _ => new KeyValuePair <string, string>("station_status", "Station status"), SystemInformationDTO _ => new KeyValuePair <string, string>("system_information", "GBFS System information"), VehicleTypesDTO _ => new KeyValuePair <string, string>("vehicle_types", "Vehicle Types"), _ => throw new NotSupportedException($"The type {typeof(T).FullName} is not a supported GBFS resource."), });
public void MakeStation(StationDTO stationDto) { Station station = new Station { Name = stationDto.Name, Locality = stationDto.Locality, Description = stationDto.Description }; _Database.Stations.Create(station); _Database.Save(); }
public ActionResult EditStation(int?id) { StationDTO stationDto = _stationService.GetStation(id); if (stationDto == null) { throw new ValidationException("Не установлено id станции", ""); } var mapper = new MapperConfiguration(cfg => cfg.CreateMap <StationDTO, StationViewModel> ()).CreateMapper(); var stationView = mapper.Map <StationDTO, StationViewModel>(stationDto); return(View(stationView)); }
public async Task <IActionResult> Create(StationDTO stationDTO) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <StationDTO, Station>(); }); IMapper mapper = config.CreateMapper(); var station = mapper.Map <StationDTO, Station>(stationDTO); _context.Add(station); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IHttpActionResult> GetStationData() { try { StationDTO stationDTO = null; //need async service method. return(Ok(stationDTO)); } catch (Exception ex) { HandleErrors(ex, "StationImageController_UpdateStationImage", "", ""); return(InternalServerError(ex)); } }
public async Task <StationDTO> GetStationData() { StationDTO stationDTO = null; //using (RiverWatchEntities _db = new RiverWatchEntities()) //{ // stationDTO = (from sti in _db.StationImages // select new StationDTO // { // }) //} return(stationDTO); }
public async Task <long> Save(StationDTO entity) { try { if (entity.Id > 0) { await _accountingSharedDSL.UpdateAccountName(entity.Id, entity.OwnerName); } return(await _stationDAL.Save(_mapper.Map <Station>(entity))); } catch (Exception ex) { return(0); } }
public ActionResult CreateStation(StationViewModel station) { try { var stationDto = new StationDTO { Name = station.Name, Locality = station.Locality, Description = station.Description }; _stationService.MakeStation(stationDto); return(Content("Вы успешно создали станцию")); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); } return(View(station)); }
public ActionResult Index() { if (User.IsInRole("Admin")) { var myStations = db.Stations.ToList(); var indexCompanyDTO = new IndexCompanyDTO(); indexCompanyDTO.myStations = myStations; return(View("../Home/IndexCompany", indexCompanyDTO)); } var StationDTO = new StationDTO(db.Stations.Where(e => e.Status == "Accepted" || e.Status == "accepted").ToList()); return(View(StationDTO)); }
public async Task <IActionResult> Create([FromBody] StationDTO stationDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var station = Mapper.Map <StationDTO, Station>(stationDTO); await _unitofWork.StationRepository.AddAsync(station); await _unitofWork.Commit(); station = await _unitofWork.StationRepository.SingleOrDefault(p => p.Id == station.Id); return(Ok(Mapper.Map <Station, StationDTO>(station))); }
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())); }
public void CreateStation(StationDTO stationDTO) { using (var uow = UnitOfWorkProvider.Create()) { var station = Mapper.Map <Station>(stationDTO); stationCreateQuery.Filter = new StationFilter { Name = stationDTO.Name, Town = stationDTO.Town }; var existedSameStation = stationCreateQuery.Execute(); if (existedSameStation != null && existedSameStation.Count != 0) { throw new ArgumentException("This station already exists"); } stationRepository.Insert(station); uow.Commit(); } }
public ActionResult PostPoint(StationDTO dto) { var station = new Location(); station.GeoLat = dto.GeoLat; station.GeoLong = dto.GeoLong; station.PlaceCategory = dto.PlaceCategory; station.PlaceName = dto.PlaceName; station.ToiletAvail = dto.ToiletAvail; station.TrafficLightAvail = dto.TrafficLightAvail; station.MenuAvail = dto.MenuAvail; station.VisualAvail = dto.VisualAvail; var random = new Random((int)DateTime.Now.Ticks); var value = random.Next(0, 3); station.AvailabilityType = (AvailabilityType)random.Next(0, 3); _dbContext.Locations.Add(station); _dbContext.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
/// <summary> /// Converts this instance of <see cref="StationDTO"/> to an instance of <see cref="Station"/>. /// </summary> /// <param name="dto"><see cref="StationDTO"/> to convert.</param> public static Station ToEntity(this StationDTO dto) { if (dto == null) { return(null); } var entity = new Station(); entity.ID = dto.ID; entity.Code = dto.Code; entity.Name = dto.Name; entity.CreatedByUserID = dto.CreatedByUserID; entity.CreatedDate = dto.CreatedDate; entity.ModifiedByUserID = dto.ModifiedByUserID; entity.ModifiedDate = dto.ModifiedDate; entity.IsActive = dto.IsActive; dto.OnEntity(entity); return(entity); }
/// <summary> /// Converts this instance of <see cref="Station"/> to an instance of <see cref="StationDTO"/>. /// </summary> /// <param name="entity"><see cref="Station"/> to convert.</param> public static StationDTO ToDTO(this Station entity) { if (entity == null) { return(null); } var dto = new StationDTO(); dto.ID = entity.ID; dto.Code = entity.Code; dto.Name = entity.Name; dto.CreatedByUserID = entity.CreatedByUserID; dto.CreatedDate = entity.CreatedDate; dto.ModifiedByUserID = entity.ModifiedByUserID; dto.ModifiedDate = entity.ModifiedDate; dto.IsActive = entity.IsActive; entity.OnDTO(dto); return(dto); }
public static IEnumerable <StationDTO> GetAllStations() { try { var query = DataLayer.Client.Cypher .Match("(s:Station)") .Return <Station>("s") .Results; if (query != null && query.Count <Station>() > 0) { return(StationDTO.FromEnitityList(query)); } return(new List <StationDTO>()); } catch (Exception e) { return(new List <StationDTO>()); } }
public async Task <IActionResult> Update(int id, [FromBody] StationDTO stationDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var stationinDb = await _unitofWork.StationRepository.SingleOrDefault(p => p.Id == id); if (stationinDb == null) { return(NotFound()); } Mapper.Map <StationDTO, Station>(stationDTO, stationinDb); await _unitofWork.Commit(); var result = Mapper.Map <Station, Station>(stationinDb); return(Ok(result)); }
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())); }
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)); }