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); }
public Result <int> Patch(int id, [FromBody] SpecialistForUpdateModel specialistUpdateModel) { if (specialistUpdateModel == null) { return(Result <int> .InvalidData); } SpecialistDTO foundSpecialist = specialistManagementService.GetById(id); if (foundSpecialist == null) { return new Result <int>() { MessageType = MessageType.NotFound, MessageText = $"Specialist with id {id} was not found" } } ; 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 }); } specialistUpdateModel.Id = id; specialistManagementService.Update(specialistUpdateMapper.MapFrom(specialistUpdateModel)); return(new Result <int>(id) { MessageType = MessageType.Ok, MessageText = $"Specialist with ID {id} was successfully updated" }); }
public Result <int> Patch(int id, [FromBody] RequestForUpdateModel updatedRequest) { if (updatedRequest == null) { return(Result <int> .InvalidData); } RequestDTO request = requestManagementService.GetById(id); if (request == null) { return new Result <int>() { MessageType = MessageType.NotFound, MessageText = $"Request with id {id} was not found" } } ; updatedRequest.Id = id; requestManagementService.Update(requestUpdateMapper.MapFrom(updatedRequest)); return(new Result <int>(id) { MessageType = MessageType.Ok, MessageText = $"Request with ID {id} was successfully updated" }); }