示例#1
0
        public IActionResult CreateGoal([FromBody] GoalPL goal)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(400, "Model is not valid"));
            }

            try
            {
                var newGoal = mapper.Map <GoalDto>(goal);
                var created = goalService.CreateGoal(newGoal);
                if (created == true)
                {
                    return(StatusCode(201, "Goal was created."));
                }
                else
                {
                    return(StatusCode(500, "Unable to create goal."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "Internal server error. Exception message: " + ex));
            }
        }
示例#2
0
        public IActionResult DeleteGoal([FromBody] GoalPL goal)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(400, "Model is not valid"));
            }

            try
            {
                var delGoal = mapper.Map <GoalDto>(goal);
                var deleted = goalService.DeleteGoal(delGoal);
                if (deleted == true)
                {
                    return(StatusCode(204, "Goal was deleted."));
                }
                else
                {
                    return(StatusCode(404, $"Unable to delete goal. Goal with id:[{goal.GoalId}] is not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "Internal server error. Exception message: " + ex));
            }
        }