public static async Task <IActionResult> SaveLinks( [HttpTrigger(AuthorizationLevel.Function, "POST", Route = "links")] HttpRequest req, [CosmosDB( databaseName: "linkylinkdb", collectionName: "linkbundles", ConnectionStringSetting = "LinkLinkConnection" )] IAsyncCollector <LinkBundle> documents, ILogger log) { TrackRequestHeaders(req, $"{nameof(GetLinks)}-HeaderData"); try { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var linkDocument = JsonConvert.DeserializeObject <LinkBundle>(requestBody); if (!ValidatePayLoad(linkDocument, req, out ProblemDetails problems)) { log.LogError(problems.Detail); return(new BadRequestObjectResult(problems)); } string handle = GetTwitterHandle(req); linkDocument.UserId = handle; EnsureVanityUrl(linkDocument); Match match = Regex.Match(linkDocument.VanityUrl, VANITY_REGEX, RegexOptions.IgnoreCase); if (!match.Success) { // does not match return(new BadRequestResult()); } if (!await BlackListChecker.Check(linkDocument.VanityUrl)) { ProblemDetails blacklistProblems = new ProblemDetails { Title = "Could not create link bundle", Detail = "Vanity link is invalid", Status = StatusCodes.Status400BadRequest, Type = "/linkylink/clientissue", Instance = req.Path }; log.LogError(problems.Detail); return(new BadRequestObjectResult(blacklistProblems)); } await documents.AddAsync(linkDocument); return(new CreatedResult($"/{linkDocument.VanityUrl}", linkDocument)); } catch (DocumentClientException ex) when(ex.StatusCode == HttpStatusCode.Conflict) { log.LogError(ex, ex.Message); ProblemDetails exceptionDetail = new ProblemDetails { Title = "Could not create link bundle", Detail = "Vanity link already in use", Status = StatusCodes.Status400BadRequest, Type = "/linkylink/clientissue", Instance = req.Path }; return(new BadRequestObjectResult(exceptionDetail)); } catch (Exception ex) { log.LogError(ex, ex.Message); return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public void OrderValidationStepInitial(IUnitOfWork db, ITime time, CompanyDTO company, DTOMarketOrder marketOrder, IList <ListingOrderDTO> orderItems, Order dbOrder) { //var upgradeChecker = new UpgradeOrderChecker(_log, _time); //var result = upgradeChecker.Check(db, marketOrder, orderItems); //upgradeChecker.ProcessResult(result, dbOrder); var duplicateChecker = new DuplicateChecker(_log, _emailService, _time); var result = duplicateChecker.Check(db, marketOrder, orderItems); duplicateChecker.ProcessResult(result, dbOrder); var insureChecker = new InsureChecker(_log, _orderHistory); result = insureChecker.Check(db, marketOrder); insureChecker.ProcessResult(result, dbOrder); var primeChecker = new PrimeChecker(_log); result = primeChecker.Check(db, marketOrder); primeChecker.ProcessResult(result, dbOrder); var dhlChecker = new DhlChecker(_log); result = dhlChecker.Check(db, marketOrder, orderItems); dhlChecker.ProcessResult(result, dbOrder); var blackListChecker = new BlackListChecker(_log, _time); result = blackListChecker.Check(db, marketOrder); blackListChecker.ProcessResult(result, dbOrder); var restockChecker = new RestockChecker(_log, _time); result = restockChecker.Check(db, marketOrder, orderItems); restockChecker.ProcessResult(result, dbOrder); var signConfirmationByOrderCostChecker = new SignConfirmationByOrderCostChecker(_log, _time, db); result = signConfirmationByOrderCostChecker.Check( marketOrder, orderItems); signConfirmationByOrderCostChecker.ProcessResult(result, dbOrder); var replaceFrenchChecker = new ReplaceFrenchCharsChecker(_log, _time); result = replaceFrenchChecker.Check(db, marketOrder, orderItems, (AddressValidationStatus)dbOrder.AddressValidationStatus); replaceFrenchChecker.ProcessResult(result, dbOrder); //var signConfirmationByServiceTypeChecker = new SignConfirmationByServiceTypeChecker(_log, db, _emailService, _time); //result = signConfirmationByServiceTypeChecker.Check(marketOrder, // orderItems); //signConfirmationByServiceTypeChecker.ProcessResult(result, dbOrder, marketOrder, orderItems); //var signConfirmationRemoveBuyerAskedBeforeChecker = new SignConfirmationRemoveBuyerAskedBeforeChecker(_log, db, _emailService, _time); //result = signConfirmationRemoveBuyerAskedBeforeChecker.Check(marketOrder, // orderItems); //signConfirmationRemoveBuyerAskedBeforeChecker.ProcessResult(result, dbOrder, marketOrder, orderItems); var oversoldChecker = new OversoldChecker(_log, _time, _emailService, _settings); result = oversoldChecker.Check(db, marketOrder, orderItems); oversoldChecker.ProcessResult(result, dbOrder); var oversoldOnHoldChecker = new OnHoldOversoldChecker(_log, _time, _emailService); result = oversoldOnHoldChecker.Check(db, marketOrder, orderItems); oversoldOnHoldChecker.ProcessResult(result, dbOrder); CheckAddressStep(db, dbOrder, marketOrder.GetAddressDto()); var recipientNameChecker = new RecipientNameChecker(_log, _emailService, _time, () => CheckAddressStep(db, dbOrder, marketOrder.GetAddressDto())); result = recipientNameChecker.Check(db, marketOrder, orderItems, (AddressValidationStatus)dbOrder.AddressValidationStatus); recipientNameChecker.ProcessResult(result, dbOrder); //NOTE: recheck address if name was corected if (result.IsSuccess) { CheckAddressStep(db, dbOrder, marketOrder.GetAddressDto()); } var zipCodeChecker = new ZipCodeChecker(_log, _time); result = zipCodeChecker.Check(db, marketOrder, orderItems, (AddressValidationStatus)dbOrder.AddressValidationStatus); zipCodeChecker.ProcessResult(result, dbOrder); var shippingStateChecker = new ShippingStateChecker(_log, _time); result = shippingStateChecker.Check(db, marketOrder, orderItems, (AddressValidationStatus)dbOrder.AddressValidationStatus); shippingStateChecker.ProcessResult(result, dbOrder); var phoneNumberChecker = new PhoneNumberChecker(_log, _emailService, _time); result = phoneNumberChecker.Check(db, marketOrder, orderItems, (AddressValidationStatus)dbOrder.AddressValidationStatus); phoneNumberChecker.ProcessResult(result, dbOrder); var dismissFFAddressChecker = new DismissFFAddressChecker(_log, _emailService, db, _time); result = dismissFFAddressChecker.Check(db, marketOrder, orderItems, (AddressValidationStatus)dbOrder.AddressValidationStatus); dismissFFAddressChecker.ProcessResult(result, dbOrder); //var addressNotServedByUSPSChecker = new AddressNotServedByUSPSChecker(_log, _htmlScraper, _emailService, _time); //result = addressNotServedByUSPSChecker.Check(db, // marketOrder, // orderItems, // (AddressValidationStatus)dbOrder.AddressValidationStatus); //addressNotServedByUSPSChecker.ProcessResult(result, dbOrder); var internationalExpressChecker = new InternationalExpressChecker(_log, _time); result = internationalExpressChecker.Check(marketOrder); internationalExpressChecker.ProcessResult(db, result, dbOrder); var sameDayChecker = new SameDayChecker(_log, _time); result = sameDayChecker.Check(marketOrder); sameDayChecker.ProcessResult(db, result, dbOrder); var noWeightChecker = new NoWeightChecker(_log, _emailService, _time, company); result = noWeightChecker.Check(db, marketOrder, orderItems); noWeightChecker.ProcessResult(result, dbOrder); dbOrder.CheckedDate = _time.GetAppNowTime(); dbOrder.CheckedTimes = dbOrder.CheckedTimes + 1; db.Commit(); }