Exemple #1
0
        public IActionResult UpdateOrganisation(int id, NewOrganisationDto updatedValues)
        {
            try
            {
                _unitOfWorkManager.StartUnitOfWork();
                Organisation updatedOrganisation = _organisationManager.ChangeOrganisation(
                    id,
                    updatedValues.Name,
                    updatedValues.Identifier,
                    updatedValues.Description,
                    updatedValues.Color);
                _unitOfWorkManager.EndUnitOfWork();

                if (updatedOrganisation == null)
                {
                    return(BadRequest("Something went wrong while updating the organisation."));
                }

                return(Ok(_mapper.Map <OrganisationDto>(updatedOrganisation)));
            }
            catch (ValidationException ve)
            {
                return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}"));
            }
            catch (ArgumentException e)
            {
                return(NotFound(e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemple #2
0
        public IActionResult PostNewOrganisation(NewOrganisationDto newOrg)
        {
            try
            {
                _unitOfWorkManager.StartUnitOfWork();
                Organisation org = _organisationManager.AddOrganisation(newOrg.Name, newOrg.Identifier, newOrg.Description, newOrg.Color);
                _unitOfWorkManager.EndUnitOfWork();

                return(CreatedAtAction(
                           "GetOrganisation",
                           new { id = org.OrganisationId },
                           _mapper.Map <OrganisationDto>(org)
                           ));
            }
            catch (ValidationException ve)
            {
                return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}"));
            }
            catch (Exception e)
            {
                var msg = e.InnerException != null ? e.InnerException.Message : e.Message;
                return(BadRequest($"Something went wrong in creating the organisation: {msg}."));
            }
        }