示例#1
0
        public async Task <ConsultantResponse> InsertAsync(Consultant consultant)
        {
            try
            {
                var existingConsultant = await _consultantRepository.GetById(consultant.ID);

                if (existingConsultant != null)
                {
                    return(new ConsultantResponse("Invalid consultant."));
                }

                var c = await _consultantRepository.Insert(consultant);

                var rec = await _consultantRepository.GetById(c.RecommendatoryID);

                //Check recommendatory:
                if (rec == null || c.ID == c.RecommendatoryID || rec.RecommendatoryID == c.ID)
                {
                    return(new ConsultantResponse("Recommendatory error!!!"));
                }

                await _unitOfWork.CompleteAsync();

                return(new ConsultantResponse(consultant));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new ConsultantResponse($"An error occurred when saving the Consultant: {ex.Message}"));
            }
        }