Ejemplo n.º 1
0
        public async Task <IActionResult> GetActivities([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var activities = await _activitiesRepository.GetActivity(id);

            if (activities == null)
            {
                return(NotFound());
            }

            return(Ok(activities));
        }
Ejemplo n.º 2
0
        public async Task <Unit> Handle(EditCommand request, CancellationToken cancellationToken)
        {
            Activity activity = await _repository.GetActivity(request.Id);

            if (activity == null)
            {
                throw new RestException(HttpStatusCode.NotFound, new{ activity = "Not Found" });
            }

            activity.Title       = request.Title ?? activity.Title;
            activity.Description = request.Description ?? activity.Description;
            activity.Category    = request.Category ?? activity.Category;
            activity.Date        = request.Date ?? activity.Date;
            activity.City        = request.City ?? activity.City;
            activity.Venue       = request.Venue ?? activity.Venue;

            bool success = await _repository.Update(activity);

            if (success)
            {
                return(Unit.Value);
            }

            throw new Exception("Problem With Saving");
        }
Ejemplo n.º 3
0
 public async Task<Activity> Handle(DetailsQuery request, CancellationToken cancellationToken)
 {
     var activity = await _repository.GetActivity(request.Id);
     
     if (activity == null)
         throw new RestException(HttpStatusCode.NotFound, new{activity = "Not Found"});
     
     return activity;
 }
Ejemplo n.º 4
0
        public async Task <Unit> Handle(DeleteCommand request, CancellationToken cancellationToken)
        {
            Activity activity = await _repository.GetActivity(request.Id);

            if (activity == null)
            {
                throw new RestException(HttpStatusCode.NotFound, new{ activity = "Not Found" });
            }

            bool success = await _repository.Delete(activity);

            if (success)
            {
                return(Unit.Value);
            }

            throw new Exception("Problem with saving changes");
        }
        public async Task GetActivityByIdRepoTest_VerifyIfIdIsCorrect()
        {
            var activityId = 4002;
            var activity1  = new Activities()
            {
                Id          = 1,
                UserId      = "aa",
                Description = "Hello",
                DateTime    = new DateTime()
            };

            dataRepository.Setup(x => x.FirstAsync(It.IsAny <Expression <Func <Activities, bool> > >()))
            .Returns(Task.FromResult(activity1));

            var result = await activitiesRepository.GetActivity(activityId);

            //dataRepository.Verify(x => x.FindAsync<Activities>(It.IsAny<int>()), Times.Once);

            Assert.Equal(result.Id, activity1.Id);
        }
Ejemplo n.º 6
0
        public async Task <BL.Models.Activity> GetActivity(int id)
        {
            var activity = await _activitiesRepository.GetActivity(id);

            return(activity);
        }