Пример #1
0
        public async Task <IHttpActionResult> Post(NameCheckBatchModel model)
        {
            if (model == null)
            {
                return(BadRequest("Missing data"));
            }
            if (String.IsNullOrWhiteSpace(model.Value))
            {
                return(BadRequest("Missing batch data"));
            }

            try
            {
                model = await Provider.NameCheckBatchAsync(model.Value, Constants.DefaultBatchSeparator, EndpointType.Api, Request.GetClientIpAddress());

                await DataService.SaveAsync(model);
            }
            catch
            {
                // TODO : Log it
                return(InternalServerError());
            }

            return(Ok(model));
        }
Пример #2
0
        public async Task <ActionResult> Batch(NameCheckBatchViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(RedirectToAction("batch"));
            }

            viewModel.History = ReadOrCreateSessionItem <List <NameCheckBatchModel> >(Constants.SessionKeys.NameCheckBatchHistory);

            if (ModelState.IsValid)
            {
                NameCheckBatchModel model = await Provider.NameCheckBatchAsync(
                    viewModel.Batch,
                    viewModel.Separator,
                    EndpointType.Website,
                    Request.UserHostAddress);

                await NameCheckBatchDataService.SaveAsync(model);

                viewModel.History.Add(model);
                SaveOrCreateSessionItem(Constants.SessionKeys.NameCheckBatchHistory, viewModel.History);
                viewModel.Batch = null;
                ModelState.Clear();
            }
            return(View(viewModel));
        }
Пример #3
0
        public async Task <NameCheckBatchModel> NameCheckBatchAsync(string value, string separator, EndpointType endpointType = EndpointType.NotSet, string userIp = null)
        {
            Guard.ArgumentNotNullOrWhiteSpace(value, "value");
            Stopwatch timer = new Stopwatch();

            timer.Start();
            IList <string> parsedBatch = NameCheckHelper.ParseBatch(value, String.IsNullOrWhiteSpace(separator) ? Constants.DefaultBatchSeparator : separator);

            var result = new NameCheckBatchModel();

            if (parsedBatch == null)
            {
                return(result);
            }
            result.Value        = value;
            result.NameChecks   = new List <NameCheckModel>();
            result.Id           = DescendingSortedGuid.NewSortedGuid();
            result.DateUtc      = DateTime.UtcNow;
            result.EndpointType = endpointType;
            result.UserIp       = userIp;


            foreach (var item in parsedBatch)
            {
                result.NameChecks.AddIfNotNull(await NameCheckAsync(item, endpointType));
            }
            timer.Stop();
            result.BatchDurationMs = timer.ElapsedMilliseconds;
            return(result);
        }