public static SleepActivityViewModel AsViewModel(this SleepActivity model, Baby baby = null) { if (model == null) { return(null); } var startDate = model.StartTime.ToLocalTime(); return(new SleepActivityViewModel { Id = model.Id, StartDate = startDate, StartTime = startDate.TimeOfDay, EndTime = model.EndTime.HasValue ? model.EndTime.Value.ToLocalTime() : (DateTimeOffset?)null, Duration = model.EndTime.HasValue ? model.EndTime.Value - model.StartTime : DateTimeOffset.Now - model.StartTime, Notes = model.Notes, HowBabyFelt = (Feeling?)model.HowBabyFelt, HowParentFelt = (Feeling?)model.HowParentFelt, Baby = baby != null?baby.AsViewModel() : new BabyViewModel { Id = model.BabyId } }); }
public static MeasurementViewModel AsViewModel(this Measurement model, bool useMetricUnits, Baby baby = null) { if (model == null) { return(null); } var length = model.Length.HasValue ? Math.Round(useMetricUnits ? model.Length.Value : model.Length.Value * Constants.UNITCONVERSION_CENTIMETRES_INCHES, 2) : model.Length; var weight = model.Weight.HasValue ? Math.Round(useMetricUnits ? model.Weight.Value : model.Weight.Value * Constants.UNITCONVERSION_KILOGRAMS_POUNDS, 2) : model.Weight; return(new MeasurementViewModel { Id = model.Id, //CreatedAt = model.CreatedAt, Length = length, Weight = weight, Baby = baby != null?baby.AsViewModel() : new BabyViewModel { Id = model.BabyId } }); }
public static MeasurementViewModel AsViewModel(this Measurement model, Baby baby = null) { return(new MeasurementViewModel { Id = model.Id, CreatedAt = model.CreatedAt, Length = model.Length, Weight = model.Weight, Baby = baby != null?baby.AsViewModel() : new BabyViewModel { Id = model.BabyId } }); }
public static SleepActivityViewModel AsViewModel(this SleepActivity model, Baby baby = null) { return(new SleepActivityViewModel { Id = model.Id, StartTime = model.StartTime, EndTime = model.EndTime, Duration = model.EndTime.HasValue ? Convert.ToInt32((model.StartTime - model.EndTime.Value).TotalMinutes) : 0, Notes = model.Notes, HowBabyFelt = model.HowBabyFelt, HowParentFelt = model.HowParentFelt, Baby = baby != null?baby.AsViewModel() : new BabyViewModel { Id = model.BabyId } }); }
public static FeedActivityViewModel AsViewModel(this FeedActivity model, bool useMetricUnits, Baby baby = null) { if (model == null) { return(null); } var startDate = model.StartTime.ToLocalTime(); var millilitresConsumed = model.AmountConsumed.HasValue ? useMetricUnits ? model.AmountConsumed.Value : Convert.ToInt32(Math.Floor(model.AmountConsumed.Value * Constants.UNITCONVERSION_MILLILITRES_OUNCES)) : model.AmountConsumed; return(new FeedActivityViewModel { Id = model.Id, StartDate = startDate, StartTime = startDate.TimeOfDay, EndTime = model.EndTime.HasValue ? model.EndTime.Value.ToLocalTime() : (DateTimeOffset?)null, Duration = model.EndTime.HasValue ? model.EndTime.Value - model.StartTime : DateTimeOffset.Now - model.StartTime, MillilitresConsumed = millilitresConsumed, FeedingSide = model.FeedingSide.HasValue ? (Side)model.FeedingSide.Value : (Side?)null, Notes = model.Notes, HowBabyFelt = (Feeling?)model.HowBabyFelt, HowParentFelt = (Feeling?)model.HowParentFelt, CurrentVolumeUnit = useMetricUnits ? Constants.UNIT_SUFFIX_MILLILITRES : Constants.UNIT_SUFFIX_OUNCES, Baby = baby != null?baby.AsViewModel() : new BabyViewModel { Id = model.BabyId } }); }