Example #1
0
        public async Task <IActionResult> Post([FromBody] AssignmentModel assignment)
        {
            if (ModelState.IsValid)
            {
                var a = _adapter.Adapt <Assignment>(assignment);

                await _assignmentRepository.AddAsync(a);

                return(Created("/", a.Id));
            }

            return(Ok());
        }
        public async Task <AssignmentResponse> SaveAsync(Assignment assignment)
        {
            try
            {
                await _assignmentRepository.AddAsync(assignment);

                await _unitOfWork.CompleteAsync();

                return(new AssignmentResponse(assignment));
            }
            catch (Exception ex)
            {
                return(new AssignmentResponse($"An error ocurred when while saving assignment: {ex.Message}"));
            }
        }