示例#1
0
        public async Task <IActionResult> UpdateView([FromBody] ViewViewModel viewViewModel)
        {
            try
            {
                var view = await viewRepository.GetByCouseIdAndDateTime(viewViewModel.CourseId, viewViewModel.DateTime);

                if (view == null)
                {
                    View viewMapped = mapper.Map <View>(viewViewModel);
                    viewMapped.Number = 1;

                    await viewRepository.Add(viewMapped);

                    return(Ok(new
                    {
                        Results = viewMapped
                    }));
                }
                else
                {
                    view.Number += 1;
                    await viewRepository.Update(view);

                    return(Ok(new
                    {
                        Results = view
                    }));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"ErrorMesages: {e}");

                return(BadRequest(new
                {
                    Errors = new { Code = "InvalidInputParameters", Description = "Invalid Input Parameters!" }
                }));
            }
        }