Esempio n. 1
0
        protected override async Task <IProcessResult <CompanyVehicleExpenditure> > Handle(UpdateCompanyVehicleExpenditureMessage msg)
        {
            var existing = await _companyVehicleExpenditureRepo.FindByExternalId(msg.CompanyVehicleExpenditureId);

            if (existing == null ||
                msg.CompanyVehicleExpenditureId == default(Guid))
            {
                existing              = new DataAccess.EF.CompanyVehicleExpenditure();
                existing.ExternalId   = Guid.NewGuid();
                existing.Id           = 0;
                existing.LastModified = DateTimeOffset.Now;
                existing.WeekId       = WeekDTO.CreateWithWeekContaining(msg.Model.DateVehicleFirstUsed).WeekId.Value;
            }
            var updateMsg = UpdateMessage.CreateFrom(msg, existing);
            var mapped    = _mapper.Map <DataAccess.EF.CompanyVehicleExpenditure>(updateMsg);

            var saved = await _companyVehicleExpenditureRepo.SaveEntity(mapped);

            return(Success(_mapper.Map <CompanyVehicleExpenditure>(saved)));
        }
Esempio n. 2
0
        private async Task <CoreExpenditureDto> SearchForExpenditure(Guid externalId)
        {
            var afl = await arcFlashLabelExpenditureRepo.FindByExternalId(externalId);

            if (afl != null)
            {
                return new CoreExpenditureDto()
                       {
                           ExpenditureType = ExpenditureTypeEnum.ArcFlashLabelExpenditure,
                           ExternalId      = externalId
                       }
            }
            ;

            var cve = await companyVehicleExpenditureRepo.FindByExternalId(externalId);

            if (cve != null)
            {
                return new CoreExpenditureDto()
                       {
                           ExpenditureType = ExpenditureTypeEnum.CompanyVehicleExpenditure,
                           ExternalId      = externalId
                       }
            }
            ;

            var ce = await contractorExpenditureRepo.FindByExternalId(externalId);

            if (ce != null)
            {
                return new CoreExpenditureDto()
                       {
                           ExpenditureType = ExpenditureTypeEnum.ContractorExpenditure,
                           ExternalId      = externalId
                       }
            }
            ;

            var me = await miscExpenditureRepo.FindByExternalId(externalId);

            if (me != null)
            {
                return new CoreExpenditureDto()
                       {
                           ExpenditureType = ExpenditureTypeEnum.MiscExpenditure,
                           ExternalId      = externalId
                       }
            }
            ;

            var taee = await timeAndExpenceExpenditureRepo.FindByExternalId(externalId);

            if (taee != null)
            {
                return new CoreExpenditureDto()
                       {
                           ExpenditureType = ExpenditureTypeEnum.TimeAndExpenceExpenditure,
                           ExternalId      = externalId
                       }
            }
            ;

            return(null);
        }
    }
}