using System; using System.Collections.Generic; using BeWo.Data.Entities; using BeWo.Service.DCEntityMapper; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.Services; namespace BeWo.Service.Plugins { public class ServiceRecordDurationCalculator : AbstractIDSpecificDefaultClass { public virtual void CalculateRoundedDuration(ServiceRecord sr) { //Wird vor dem eigentlichen Speichern aufgerufen if (sr.CostBearer2SupportConcept != null && sr.ServiceDescription.ServiceCategory != null && sr.ServiceDescription.ServiceCategory.IsBillable) { var duration = (decimal)sr.End.Value.Subtract(sr.Start.Value).TotalMinutes; Calculations calc = Calculations.GetInstance(sr.CostBearer2SupportConcept.CostBearer.ID); var cc = MapperFactory.CompactOrganisationDC_Organisation.MapToNewDC( sr.CostBearer2SupportConcept.CostBearer.Organisation); var roundedDuration = calc.GetRoundedDuration(cc, duration); sr.RoundedDuration = roundedDuration; } else { sr.RoundedDuration = (decimal)sr.End.Value.Subtract(sr.Start.Value).TotalMinutes; } } public virtual void CalculateRoundedDuration(ServiceRecordDC newServiceRecord) { //Wird nur für die Validierung benötigt if (newServiceRecord.ServiceDescription.Category != null && newServiceRecord.ServiceDescription.Category.IsBillable && newServiceRecord.CostBearer != null) { var duration = (decimal)newServiceRecord.End.Value.Subtract(newServiceRecord.Start.Value).TotalMinutes; Calculations calc = Calculations.GetInstance(newServiceRecord.CostBearer.CostBearerID); var roundedDuration = calc.GetRoundedDuration(newServiceRecord.CostBearer, duration); newServiceRecord.RoundedDuration = roundedDuration; } } } }