public async Task <int> InsertOrUpdatePolyclinicRegionAsync(PolyclinicRegion polyclinicRegion) { ServerResponse <int> response = await this.Client.SendAsync <int>(HttpMethod.Post, "api/region", polyclinicRegion); if (response.Content == default(int)) { throw new HmsException(response.ReasonPhrase); } return(response.Content); }
public async Task <IHttpActionResult> Get(int id) { try { PolyclinicRegion region = await this.PolyclinicRegionService.GetRegionAsync(id); return(this.Ok(region)); } catch (Exception e) { return(new HttpActionResult(this, HttpStatusCode.BadRequest, e.Message)); } }
public async Task <IHttpActionResult> Post([FromBody] PolyclinicRegion polyclinicRegion) { try { if (polyclinicRegion == null) { throw new ArgumentNullException($"{nameof(polyclinicRegion)} must be not null"); } int id = await this.PolyclinicRegionService.InsertOrUpdateRegionAsync(polyclinicRegion); return(this.Ok(id)); } catch (Exception e) { return(new HttpActionResult(this, HttpStatusCode.BadRequest, e.Message)); } }
public async Task <int> InsertOrUpdateRegionAsync(PolyclinicRegion polyclinicRegion) { try { using (var connection = new SqlConnection(this.ConnectionString)) { await connection.OpenAsync(); int doctorId = await this.DoctorRepository.InsertOrUpdateDoctorAsync(polyclinicRegion.RegionHead); var command = @" BEGIN TRAN IF EXISTS (SELECT * FROM [PolyclinicRegion] WHERE [Id] = @Id) BEGIN UPDATE [PolyclinicRegion] WITH (SERIALIZABLE) SET [PolyclinicId] = @PolyclinicId, [RegionNumber] = @RegionNumber, [RegionHeadId] = @doctorId WHERE [Id] = @Id SELECT @Id END ELSE BEGIN INSERT INTO [PolyclinicRegion] ([PolyclinicId], [RegionNumber], [RegionHeadId]) OUTPUT INSERTED.Id VALUES (@PolyclinicId, @RegionNumber, @doctorId) END COMMIT TRAN"; return(await connection.ExecuteAsync(command, new { polyclinicRegion.PolyclinicId, polyclinicRegion.Id, polyclinicRegion.RegionNumber, doctorId })); } } catch (Exception e) { throw new ArgumentException(e.Message); } }
public async Task <BuildingAddress> GetBuildingAsync(GeoPoint geoPoint) { GeoObjectCollection objectCollection = await this.Geocoder.ReverseGeocodeAsync(geoPoint, GeoObjectKind.House, 1, LangType.RU); GeoObject geoObject = objectCollection.First(); Address address = geoObject.GeocoderMetaData.Address; int buildingId = await this.BuildingRepository.GetBuildingIdOrDefaultAsync(geoPoint.Latitude, geoPoint.Longitude); if (buildingId != default(int)) { return(await this.BuildingRepository.GetBuildingAsync(buildingId)); } int id = await this.PolyclinicRegionProvider.GetPolyclinicRegionIdAsync(address); PolyclinicRegion region = await this.PolyclinicRegionService.GetRegionAsync(id); BuildingAddress building = new BuildingAddress { City = $"{address.Locality}, {address.Province}, {address.Country}", Street = address.Street, Building = address.House, Latitude = geoPoint.Latitude, Longitude = geoPoint.Longitude, PolyclinicRegion = region }; int insertedBuildingId = await this.InsertOrUpdateBuildingAsync(building); building.Id = insertedBuildingId; return(building); }
public Task <int> InsertOrUpdateRegionAsync(PolyclinicRegion polyclinicRegion) { return(this.InsertOrUpdateRegionAsync(polyclinicRegion)); }