private bool IsTheFirstEntry() { GenericError error; List <DailyEnergyLevel> entries = DailyEnergyLevelRepository.GetEntities(out error, d => true); return(entries == null || entries.Count == 0); }
public bool InsertDailyEnergyLevel(DailyEnergyLevel energyLevel) { try { DateTime now = Controller.GetServerDateTime(); bool todayEnergyLevelExist = DailyEnergyLevelRepository.GetAsQueryable <DailyEnergyLevel>().ToList() .FirstOrDefault(e => (e.UserId == energyLevel.UserId) && (now.Day == e.Date.Day) && (now.Month == e.Date.Month) && (now.Year == e.Date.Year)) != null; if (todayEnergyLevelExist) { return(false); } GenericError error; DailyEnergyLevelRepository.InsertEntity(out error, energyLevel); if (error == null) { MontlyInfoHandlingTemplate.UpdateEntityRecords(energyLevel); YearlyInfoHandlingTemplate.UpdateEntityRecords(energyLevel); EventsService.UpdateUserDates(energyLevel.UserId, null, Controller.GetServerDateTime()); } return(error == null); } catch (Exception ex) { Logger.Controller.LogError(ex); ErrorClasses.Controller.GetUnknownError(); return(false); } }
private DailyEnergyLevel GetLattestDailyEnergyLevel(out GenericError error) { List <DailyEnergyLevel> lattestDailyEnergyLevel; try { lattestDailyEnergyLevel = DailyEnergyLevelRepository.GetEntities(out error, d => true).ToList(); lattestDailyEnergyLevel.Sort((d1, d2) => DateTime.Compare(d1.Date, d2.Date)); } catch (Exception ex) { Logger.Controller.LogError(ex); error = ErrorClasses.Controller.GetUnknownError(); throw; } return(lattestDailyEnergyLevel.Count > 0 ? lattestDailyEnergyLevel.Last() : new DailyEnergyLevel()); }