コード例 #1
0
        public Result <int> Post([FromBody] SpecialistForAddModel specialist)
        {
            if (specialist == null)
            {
                return(Result <int> .InvalidData);
            }
            if (!ModelState.IsValid)
            {
                string errors = string.Join(" | ", ModelState.Values
                                            .SelectMany(v => v.Errors)
                                            .Select(e => e.ErrorMessage));
                return(new Result <int>()
                {
                    MessageType = MessageType.InvalidData, MessageText = errors
                });
            }

            int specialistID = specialistManagementService.AddSpecialist(specialistAddMapper.MapFrom(specialist));

            return(new Result <int>(specialistID)
            {
                MessageType = MessageType.Created, MessageText = $"Specialist was successfully created with id {specialistID}"
            });
            // return CreatedAtRoute(nameof(GetByID), new { id = specialistID }, specialist);
        }
コード例 #2
0
 public IActionResult AddSpecialist(SpecialistDTO newSpecialist)
 {
     specialistManagementService.AddSpecialist(newSpecialist);
     return(RedirectToAction("Specialists"));
 }