public async Task <int> ChangeInformationAsync(string token, Personal personal) { NullCheck.ThrowIfNull <Personal>(personal); var query = from o in _context.offer as IQueryable <OfferEntity> join p in _context.personal on o.id equals p.offer_id where o.token == token && p.id == personal.id select new { o, p }; foreach (var collection in await query.ToListAsync()) { collection.p.qualification = personal.qualification; collection.p.institution = personal.institution; collection.p.area = personal.area; collection.p.researchgroup = personal.researchgroup; collection.p.annotation = personal.annotation; collection.p.experience_rt_pcr = personal.experience_rt_pcr; } var changedRows = await _context.SaveChangesAsync(); if (1 < changedRows) { throw new InvalidDataStateException(FatalCodes.UpdatesMadeInTooManyRows); } return(changedRows); }
public async Task <int> ChangeInformationAsync(string token, Device device) { NullCheck.ThrowIfNull <Device>(device); var query = from o in _context.offer as IQueryable <OfferEntity> join d in _context.device on o.id equals d.offer_id where o.token == token && d.id == device.id select new { o, d }; foreach (var collection in await query.ToListAsync()) { collection.d.annotation = device.annotation; collection.d.name = device.name; collection.d.manufacturer = device.manufacturer; collection.d.ordernumber = device.ordernumber; } var changedRows = await _context.SaveChangesAsync(); if (1 < changedRows) { throw new InvalidDataStateException(FatalCodes.UpdatesMadeInTooManyRows); } return(changedRows); }
public void ValidateForChangeInformation(string token, Device device) { NullCheck.ThrowIfNull <Device>(device); ValidateToken(token); validateInformation(device); }
public async Task <IActionResult> ChangeResourceAsync(string token, int id, [FromBody] Personal personal) { NullCheck.ThrowIfNull <Personal>(personal); try { personal.id = id; _resourceStockInputValidatorService.ValidateForChangeInformation(token, personal); int changedRows = await _resourceStockUpdateService.ChangeInformationAsync(token, personal); return(Ok(changedRows)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } catch (DataNotFoundException e) { return(NotFound(e.Message)); } catch (InvalidDataStateException e) { return(StatusCode(StatusCodes.Status500InternalServerError, e)); } }
public async Task <int> ChangeInformationAsync(string token, Provider provider) { NullCheck.ThrowIfNull <Provider>(provider); AddressEntity location = new AddressEntity().build(provider.address); _addressMaker.SetCoordinates(location); var query = from o in _context.offer as IQueryable <OfferEntity> join ap in _context.address on o.address_id equals ap.Id where o.token == token select new { o, ap }; foreach (var collection in await query.ToListAsync()) { collection.o.name = provider.name; //o.ispublic = provider.ispublic; //TODO everything non public so far collection.o.organisation = provider.organisation; collection.o.phone = provider.phone; collection.ap.OverwriteWith(location); } var changedRows = await _context.SaveChangesAsync(); if (2 < changedRows) { throw new InvalidDataStateException(FatalCodes.UpdatesMadeInTooManyRows); } return(changedRows); }
public async Task <IActionResult> PostAsync([FromQuery][Required] string region, [FromBody] Offer offer) { NullCheck.ThrowIfNull <Offer>(offer); try { _configurationService.ThrowIfUnknownRegion(region); _mailInputValidatorService.validateMail(offer.provider.mail); _resourceStockInputValidatorService.ValidateForStockInsertion(offer); var token = await _resourceStockUpdateService.InsertAsync(offer, region); await _mailService.SendNewOfferConfirmationMailAsync(region, token, offer.provider.mail, offer.provider.name); return(Ok(token)); } catch (UnknownAdressException e) { return(BadRequest(e.Message)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> PersonalAnonymContactAsync([FromBody] ContactInformationDemand contactInformationDemand, int id) { NullCheck.ThrowIfNull <ContactInformationDemand>(contactInformationDemand); try { _mailInputValidatorService.validateMail(contactInformationDemand.senderEmail); var personal = (PersonalEntity)await _resourceStockQueryService.FindAsync(new PersonalEntity(), id); if (personal is null) { return(NotFound(FailureCodes.NotFoundPersonal)); } var offer = (OfferEntity)await _resourceStockQueryService.FindAsync(new OfferEntity(), personal.offer_id); if (offer is null) { return(NotFound(FailureCodes.NotFoundOffer)); } var mailAddressReceiver = offer.mail; var mailUserNameReceiver = offer.name; await _mailService.SendDemandMailToProviderAsync(offer.region, contactInformationDemand, mailAddressReceiver, mailUserNameReceiver); await _mailService.SendDemandConformationMailToDemanderAsync(offer.region, contactInformationDemand); return(Ok()); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public async Task <int> ChangeInformationAsync(string token, Consumable consumable) { NullCheck.ThrowIfNull <Consumable>(consumable); var query = from o in _context.offer as IQueryable <OfferEntity> join c in _context.consumable on o.id equals c.offer_id where o.token == token && c.id == consumable.id select new { o, c }; foreach (var collection in await query.ToListAsync()) { collection.c.annotation = consumable.annotation; collection.c.unit = consumable.unit; collection.c.name = consumable.name; collection.c.manufacturer = consumable.manufacturer; collection.c.ordernumber = consumable.ordernumber; } var changedRows = await _context.SaveChangesAsync(); if (1 < changedRows) { throw new InvalidDataStateException(FatalCodes.UpdatesMadeInTooManyRows); } return(changedRows); }
public void SetCoordinates(AddressEntity address) { NullCheck.ThrowIfNull <AddressEntity>(address); string apiKey = Environment.GetEnvironmentVariable("PIRAT_GOOGLE_API_KEY"); string addressString = address.ToQueryString(); Uri uri = new Uri("https://maps.googleapis.com/maps/api/geocode/json?address=" + addressString + "&key=" + apiKey); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; string responseString; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { responseString = reader.ReadToEnd(); } JObject json = (JObject)JsonConvert.DeserializeObject(responseString); JArray result = (JArray)json.GetValue("results", StringComparison.Ordinal); if (result.Count == 0) { throw new UnknownAdressException(FailureCodes.InvalidAddress); } JObject location = (JObject)((JObject)((JObject)result[0]).GetValue("geometry", StringComparison.Ordinal)).GetValue("location", StringComparison.Ordinal); decimal lat = location.GetValue("lat", StringComparison.Ordinal).ToObject <decimal>(); decimal lng = location.GetValue("lng", StringComparison.Ordinal).ToObject <decimal>(); address.Latitude = lat; address.Longitude = lng; address.HasCoordinates = true; }
public void ValidateForChangeInformation(string token, Provider provider) { NullCheck.ThrowIfNull <Provider>(provider); ValidateToken(token); validateInformation(provider); }
public async Task <IActionResult> PostAsync([FromBody] AdminKeyProtected <Demand> adminKeyProtectedDemand) { NullCheck.ThrowIfNull <Demand>(adminKeyProtectedDemand); // This is a temporary solution until #103 is done. if (!_adminKey.Equals(adminKeyProtectedDemand.adminKey, StringComparison.InvariantCulture)) { return(StatusCode(403)); } Demand demand = adminKeyProtectedDemand.data; try { _mailInputValidatorService.validateMail(demand.provider.mail); _resourceDemandInputValidatorService.ValidateForDemandInsertion(demand); var token = await _resourceDemandUpdateService.InsertAsync(demand); return(Ok(token)); } catch (UnknownAdressException e) { return(BadRequest(e.Message)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public void ValidateForChangeInformation(string token, Consumable consumable) { NullCheck.ThrowIfNull <Consumable>(consumable); ValidateToken(token); validateInformation(consumable); }
public void ValidateForChangeInformation(string token, Personal personal) { NullCheck.ThrowIfNull <Personal>(personal); ValidateToken(token); validateInformation(personal); }
public async Task InvokeAsync(HttpContext context) { NullCheck.ThrowIfNull <HttpContext>(context); var path = context.Request.Path.ToString(); var method = context.Request.Method; if ((blackList.Contains(path) && method.ToUpper(CultureInfo.InvariantCulture).Equals(WebRequestMethods.Http.Post, StringComparison.Ordinal)) || isContactEnding(path) && method.ToUpper(CultureInfo.InvariantCulture).Equals(WebRequestMethods.Http.Post, StringComparison.Ordinal)) { var headerValue = context.Request.Headers[HeaderKey].ToString(); if (string.IsNullOrEmpty(headerValue)) { context.Response.StatusCode = StatusCodes.Status400BadRequest; await context.Response.WriteAsync("Missing ReCaptcha"); return; } if (await _captchaService.ValidateResponseAsync(headerValue)) { await _next(context); return; } else { context.Response.StatusCode = StatusCodes.Status403Forbidden; await context.Response.WriteAsync("Wrong ReCaptcha"); return; } } await _next(context); }
public async Task <IInsertable> InsertAsync(ResourceContext context) { NullCheck.ThrowIfNull <ResourceContext>(context); context.address.Add(this); await context.SaveChangesAsync(); return(this); }
public IActionResult VerifyKey([FromBody] AdminKeyVerificationRequest request) { NullCheck.ThrowIfNull <AdminKeyVerificationRequest>(request); return(Ok(new AdminKeyVerificationResponse() { success = _adminKey.Equals(request.adminKey, StringComparison.InvariantCulture) })); }
public async Task AddResourceAsync(string token, Personal personal) { NullCheck.ThrowIfNull <Personal>(personal); OfferEntity offerEntity = await _queryHelper.RetrieveOfferFromTokenAsync(token); await InsertAsync(offerEntity.id, personal); }
public async Task AddResourceAsync(string token, Device device) { NullCheck.ThrowIfNull <Device>(device); OfferEntity offerEntity = await _queryHelper.RetrieveOfferFromTokenAsync(token); await InsertAsync(offerEntity.id, device); }
public async Task AddResourceAsync(string token, Consumable consumable) { NullCheck.ThrowIfNull <Consumable>(consumable); OfferEntity offerEntity = await _queryHelper.RetrieveOfferFromTokenAsync(token); await InsertAsync(offerEntity.id, consumable); }
public DemandEntity Build(Provider p) { NullCheck.ThrowIfNull <Provider>(p); name = p.name; institution = p.organisation; phone = p.phone; mail = p.mail; return(this); }
private static void validateAddress(Address address) { NullCheck.ThrowIfNull <Address>(address); if (!address.ContainsInformation()) { throw new ArgumentException(FailureCodes.IncompleteAddress); } }
public Provider Build(DemandEntity d) { NullCheck.ThrowIfNull <DemandEntity>(d); name = d.name; organisation = d.institution; phone = d.phone; mail = d.mail; return(this); }
public Provider Build(OfferEntity o) { NullCheck.ThrowIfNull <OfferEntity>(o); name = o.name; organisation = o.organisation; phone = o.phone; mail = o.mail; ispublic = o.ispublic; return(this); }
public void ValidateForDemandQuery(Consumable consumable) { NullCheck.ThrowIfNull <Consumable>(consumable); if (string.IsNullOrEmpty(consumable.category)) { throw new ArgumentException(FailureCodes.IncompleteConsumable); } ValidateForDemandQuery(consumable.address, consumable.kilometer); }
public void ValidateForDemandQuery(Device device) { NullCheck.ThrowIfNull <Device>(device); if (string.IsNullOrEmpty(device.category)) { throw new ArgumentException(FailureCodes.IncompleteDevice); } ValidateForDemandQuery(device.address, device.kilometer); }
public void ValidateForStockInsertion(Device device) { NullCheck.ThrowIfNull <Device>(device); validateInformation(device); if (device.amount < 1) { throw new ArgumentException(FailureCodes.InvalidAmountDevice); } }
public void ValidateForStockInsertion(Consumable consumable) { NullCheck.ThrowIfNull <Consumable>(consumable); validateInformation(consumable); if (consumable.amount < 1) { throw new ArgumentException(FailureCodes.InvalidAmountConsumable); } }
public OfferEntity Build(Provider p, string region) { NullCheck.ThrowIfNull <Provider>(p); name = p.name; organisation = p.organisation; phone = p.phone; mail = p.mail; ispublic = p.ispublic; this.region = region; return(this); }
public DeviceDemandEntity Build(Device d) { NullCheck.ThrowIfNull <Device>(d); category = d.category; name = d.name; manufacturer = d.manufacturer; //ordernumber = d.ordernumber; amount = d.amount; annotation = d.annotation; return(this); }
public ConsumableDemandEntity Build(Consumable c) { NullCheck.ThrowIfNull <Consumable>(c); category = c.category; name = c.name; manufacturer = c.manufacturer; amount = c.amount; unit = c.unit; annotation = c.annotation; return(this); }