Beispiel #1
0
        public async Task <TravelPlanStatusDto> GetStatusAsync(TravelPlanStatusEnum status)
        {
            var tpStatus = await _travelPlanStatusRepository.GetStatusAsync(status);

            var tpStatusDto = new TravelPlanStatusDto()
            {
                Description = tpStatus.Description,
                UniqStatus  = tpStatus.UniqStatus
            };

            return(tpStatusDto);
        }
Beispiel #2
0
        public async Task <Dictionary <string, TravelPlanStatusDto> > SetStatusAsync(Guid travelPlanid, Guid userId, int status)
        {
            try
            {
                if (!Enum.IsDefined(typeof(TravelPlanStatusEnum), status))
                {
                    throw new Exception("Problem Setting Status of Travel Plan");
                }

                var travelPlanToEdit = await _dbContext.TravelPlans.FindAsync(travelPlanid);

                if (travelPlanToEdit == null)
                {
                    throw new Exception("Travel Plan Not Found");
                }

                if (travelPlanToEdit.CreatedById != userId)
                {
                    throw new InsufficientRightsException("Insufficient rights to edit Travel Plan");
                }

                travelPlanToEdit.TravelPlanStatusId = status;


                var tpStatusDto = await _travelPlanStatusRepository.GetStatusAsync((TravelPlanStatusEnum)status);

                if (!_dbContext.ChangeTracker.HasChanges())
                {
                    return new Dictionary <string, TravelPlanStatusDto> {
                               { travelPlanid.ToString(), tpStatusDto }
                    }
                }
                ;

                var isSuccessful = await _dbContext.SaveChangesAsync() > 0;

                if (isSuccessful)
                {
                    return(new Dictionary <string, TravelPlanStatusDto> {
                        { travelPlanid.ToString(), tpStatusDto }
                    });
                }
                throw new Exception("Problem occurred saving status of Travel Plan");
            }
            catch (Exception)
            {
                throw;
            }
        }