public IActionResult Create([FromBody] Point item) { if (item == null) { return(BadRequest()); } pointRepository.Add(item); pointHistoryService.AddHistory(item, PointHistoryType.Create); return(Json(item)); }
public async Task <ActionResult <Point> > Create(PointDto point) { bool validLimit = _pointService.ValidateLimit(await _pointRepository.GetAll()); bool isDublicate = _pointService.IsDublicate(await _pointRepository.GetAll(), point); if (validLimit && !isDublicate) { return(await _pointRepository.Add(point)); } return(null); }
public async Task CreatePointTest() { var token = new System.Threading.CancellationToken(); IPointRepository repository = Provider.GetService <IPointRepository>(); var point = await repository.Add(new Infrastructure.Persistence.DTO.Point() { Name = "A" }, token); Assert.IsNotNull(point); }
public async Task GetPointsTest() { var token = new System.Threading.CancellationToken(); IPointRepository repository = Provider.GetService <IPointRepository>(); await repository.Add(new Infrastructure.Persistence.DTO.Point() { Name = "A" }, token); await repository.Add(new Infrastructure.Persistence.DTO.Point() { Name = "B" }, token); await repository.Add(new Infrastructure.Persistence.DTO.Point() { Name = "C" }, token); var points = await repository.GetAll(token); Assert.IsNotNull(points); Assert.AreEqual(3, points.Count()); }
public void AddPoint(int userId, int filmId, int point) { var p = new PointValidator(); var result = p.Validate(point); if (result.Errors.Count != 0) { throw new Exception(string.Join("\n", result.Errors.Select(x => x.ErrorMessage))); } var t = _pointRepository.Get(userId, filmId); if (t == null) { _pointRepository.Add(userId, filmId, point); } else { _pointRepository.Update(userId, filmId, point); } }
public async Task generatePoint() { var token = new System.Threading.CancellationToken(); var pA = await repositoryPoint.Add(new Point() { Name = "A" }, token); var pB = await repositoryPoint.Add(new Point() { Name = "B" }, token); var pC = await repositoryPoint.Add(new Point() { Name = "C" }, token); var pD = await repositoryPoint.Add(new Point() { Name = "D" }, token); var pE = await repositoryPoint.Add(new Point() { Name = "E" }, token); var pF = await repositoryPoint.Add(new Point() { Name = "F" }, token); var pG = await repositoryPoint.Add(new Point() { Name = "G" }, token); var pH = await repositoryPoint.Add(new Point() { Name = "H" }, token); var pI = await repositoryPoint.Add(new Point() { Name = "I" }, token); await repository.Add(new Route() { OriginalPoint = pA, DestinationPoint = pC, Cost = 20, Time = 1 }, token); await repository.Add(new Route() { OriginalPoint = pA, DestinationPoint = pH, Cost = 10, Time = 1 }, token); await repository.Add(new Route() { OriginalPoint = pA, DestinationPoint = pE, Cost = 30, Time = 5 }, token); await repository.Add(new Route() { OriginalPoint = pC, DestinationPoint = pB, Cost = 12, Time = 1 }, token); await repository.Add(new Route() { OriginalPoint = pH, DestinationPoint = pE, Cost = 1, Time = 30 }, token); await repository.Add(new Route() { OriginalPoint = pE, DestinationPoint = pD, Cost = 5, Time = 3 }, token); await repository.Add(new Route() { OriginalPoint = pD, DestinationPoint = pF, Cost = 50, Time = 4 }, token); await repository.Add(new Route() { OriginalPoint = pF, DestinationPoint = pI, Cost = 50, Time = 45 }, token); await repository.Add(new Route() { OriginalPoint = pF, DestinationPoint = pG, Cost = 50, Time = 40 }, token); await repository.Add(new Route() { OriginalPoint = pG, DestinationPoint = pB, Cost = 73, Time = 64 }, token); await repository.Add(new Route() { OriginalPoint = pI, DestinationPoint = pB, Cost = 73, Time = 64 }, token); }