Beispiel #1
0
        public async Task <ActionResult> Create([FromBody] SpecializationDTO dto)
        {
            try
            {
                var spec    = dto.ConceptSpecialization();
                var created = await manager.CreateAsync(spec);

                return(Ok(SpecializationDTO.From(created)));
            }
            catch (FormatException fe)
            {
                logger.LogError("Malformed Specialization:{@Specialization} Error:{Error}", dto, fe.Message);
                return(BadRequest(CRUDError.From("Malformed Specialization.UniversalId.")));
            }
            catch (ArgumentException ae)
            {
                logger.LogError("Invalid create Specialization model. Model:{@Model} Error:{Error}", dto, ae.Message);
                return(BadRequest(CRUDError.From($"{nameof(Specialization)} is missing or incomplete.")));
            }
            catch (LeafRPCException le)
            {
                return(StatusCode(le.StatusCode, CRUDError.From(le.Message)));
            }
            catch (Exception e)
            {
                logger.LogError("Failed to create Specialization:{@Specialization} Error:{Error}", dto, e.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <ActionResult> Update(Guid id, [FromBody] SpecializationDTO dto)
        {
            try
            {
                if (dto == null)
                {
                    return(BadRequest(CRUDError.From("Specialization is missing.")));
                }
                if (dto.SpecializationGroupId == default)
                {
                    return(BadRequest(CRUDError.From("Specialization.SpecializationGroupId is required.")));
                }
                if (string.IsNullOrWhiteSpace(dto.UiDisplayText))
                {
                    return(BadRequest(CRUDError.From("Specialization.UiDisplayText is required.")));
                }
                if (string.IsNullOrWhiteSpace(dto.SqlSetWhere))
                {
                    return(BadRequest(CRUDError.From("Specialization.SqlSetWhere is required.")));
                }
                dto.Id = id;

                var spec    = dto.ConceptSpecialization();
                var updated = await specializationService.Update(spec);

                if (updated == null)
                {
                    return(NotFound());
                }
                return(Ok(SpecializationDTO.From(updated)));
            }
            catch (FormatException fe)
            {
                logger.LogError("Malformed Specialization:{@Specialization} Error:{Error}", dto, fe.Message);
                return(BadRequest(CRUDError.From("Malformed Specialization.UniversalId.")));
            }
            catch (LeafDbException le)
            {
                return(StatusCode(le.StatusCode, CRUDError.From(le.Message)));
            }
            catch (Exception e)
            {
                logger.LogError("Could not update Specialization:{@Specialization} Error:{Error}", dto, e.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }