public IActionResult Put(int id, [FromBody] ActivityModel updatedActivity)
        {
            var activity = _activityService.Update(updatedActivity.ToDomainModel());

            if (activity == null)
            {
                return(NotFound());
            }
            return(Ok(activity.ToApiModel()));
        }
Example #2
0
        public IActionResult Put(int id, [FromBody] ActivityModel updatedActivity)
        {
            // TODO: convert updatedAuthor to a domain model
            var activity = _activityRepository.Update(updatedActivity.ToDomainModel());

            if (activity == null)
            {
                return(NotFound());
            }
            return(Ok(activity));
        }
        public IActionResult Put(int id, [FromBody] ActivityModel activity)
        {
            activity.Id = id;
            var tempActivity = _activityService.Update(activity.ToDomainModel());

            if (tempActivity == null)
            {
                return(NotFound());
            }
            return(Ok(tempActivity));
        }
 public IActionResult Post([FromBody] ActivityModel activity)
 {
     try
     {
         return(Ok(_activityService.Add(activity.ToDomainModel())));
     }
     catch (Exception e)
     {
         ModelState.AddModelError("Post", e.Message);
         return(BadRequest(ModelState));
     }
 }
Example #5
0
 public IActionResult Post([FromBody] ActivityModel activity)
 {
     try
     {
         _activityService.Add(activity.ToDomainModel());
     }
     catch (System.Exception ex)
     {
         ModelState.AddModelError("AddActivity", ex.GetBaseException().Message);
         return(BadRequest(ModelState));
     }
     return(CreatedAtAction("Get", new { Id = activity.Id }, activity));
 }
        public IActionResult Put(int id, [FromBody] ActivityModel activity)
        {
            var current = _activityService.Get(id);

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

            current = _activityService.Update(activity.ToDomainModel());

            return(Ok(current));
        }
Example #7
0
        public IActionResult Put(int id, [FromBody] ActivityModel updatedActivity)
        {
            var activity = _activityService.Update(updatedActivity.ToDomainModel());

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

            if (activity.UserId != CurrentUserId && !User.IsInRole("Admin"))
            {
                ModelState.AddModelError("UserId", "You can only update your own activities.");
                return(BadRequest(ModelState));
            }
            return(Ok(activity.ToApiModel()));
        }
Example #8
0
        public IActionResult Post([FromBody] ActivityModel newActivity)
        {
            try
            {
                // TODO: convert the newAuthor to a domain model
                // add the new author
                _activityRepository.Add(newActivity.ToDomainModel());
            }
            catch (System.Exception ex)
            {
                ModelState.AddModelError("AddActivity", ex.GetBaseException().Message);
                return(BadRequest(ModelState));
            }

            // return a 201 Created status. This will also add a "location" header
            // with the URI of the new author. E.g., /api/authors/99, if the new is 99
            return(CreatedAtAction("Get", new { Id = newActivity.Id }, newActivity));
        }