Beispiel #1
0
        public void CreateTest()
        {
            bool actual = _sampleService.Create(new EfSample()
            {
                UserName = "******" + DateTime.Now.ToString("MMddHHmmss")
            });

            Assert.IsTrue(actual);

            actual = _sampleService.Create(new EfSample()
            {
                UserName = "******" + DateTime.Now.ToString("MMddHHmmss")
            });
            Assert.IsTrue(actual);

            actual = _sampleService.Create(new EfSample()
            {
                UserName = "******" + DateTime.Now.ToString("MMddHHmmss")
            });
            Assert.IsTrue(actual);

            actual = _sampleService.Create(new EfSample()
            {
                UserName = "******" + DateTime.Now.ToString("MMddHHmmss")
            });
            Assert.IsTrue(actual);

            actual = _sampleService.Create(new EfSample()
            {
                UserName = "******" + DateTime.Now.ToString("MMddHHmmss")
            });
            Assert.IsTrue(actual);
        }
Beispiel #2
0
        public async Task <bool> SeedDatabaseAsync()
        {
            var sampleSeed = _seedOptions.Value.SampleSeed;

            sampleSeed.CheckArgumentIsNull(nameof(sampleSeed));

            const string thisMethodName = nameof(SeedDatabaseAsync);

            var sampleExists = await _sampleService.Exists();

            if (sampleExists)
            {
                _logger.LogInformation($"{thisMethodName}: Sample is already exists.");
                return(true);
            }

            //Create the `Sample` if it does not exist

            var sampleResult = await _sampleService.Create(new SampleViewModel
            {
                Title = sampleSeed.Title
            });

            if (sampleResult <= 0)
            {
                _logger.LogError($"{thisMethodName}: Sample CreateAsync failed. {sampleResult}");
                return(false);
            }

            _logger.LogInformation($"{thisMethodName}: Sample already exists.");
            return(true);
        }
Beispiel #3
0
        public void CreateTest()
        {
            // ReSharper disable once StringLiteralTypo
            bool actual = _sampleService.Create(new EfSample()
            {
                UserName = "******" + DateTime.Now.ToString("MMddHHmmss")
            });

            Assert.IsTrue(actual);
        }
Beispiel #4
0
        public async Task <IActionResult> Create(SampleViewModel viewModel)
        {
            try
            {
                var result = await _sampleService.Create(viewModel);

                if (result > 0)
                {
                    return(BaseOk());
                }
                return(BaseBadRequest());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(StatusCode(500, ex.Message));
            }
        }
Beispiel #5
0
        public IActionResult Create([FromBody] Sample example)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                _sampleService.Create(example);

                return(Ok("Example created sucessfuly!"));
            }
            catch (ApplicationException appException)
            {
                return(NotFound(appException.Message));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
        public SampleModule(ISampleService svc)
            : base("/samples")
        {
            Get["/"] = x =>
            {
                return(Response.AsJson <object>(svc.GetAll()));
            };

            Get["/sensor/{sensorId}"] = parameters =>
            {
                List <Sample> samples = svc.GetBySensor(parameters.sensorId);
                return(Response.AsJson <object>(samples));
            };

            Post["/"] = _ =>
            {
                try
                {
                    var sample = this.Bind <Sample>();
                    sample.Timestamp = DateTime.UtcNow;

                    if (String.IsNullOrWhiteSpace(sample.SensorId))
                    {
                        throw new Exception("invalid sensorId");
                    }

                    svc.Create(sample);
                }
                catch (Exception)
                {
                    return(HttpStatusCode.BadRequest);
                }

                return(HttpStatusCode.OK);
            };
        }
Beispiel #7
0
        public ActionResult <Journey> Create(Journey journey)
        {
            _sampleService.Create(journey);

            return(CreatedAtRoute("GetJourney", new { id = journey.Id }, journey));
        }