コード例 #1
0
        public IHttpActionResult Post([FromBody] WorkCreateDto work)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                Work newWork = new Work
                {
                    ComposerID  = work.ComposerId,
                    Title       = work.Title,
                    EraID       = work.EraId,
                    Description = work.Description,
                    Year        = work.Year
                };

                workService.Add(newWork);
                workService.Save();

                var dtoWork = new WorkDto(newWork);
                return(Ok(dtoWork));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }