public TStatusModelDto GetStatusModel(TContextDto context) { try { var calc = new TracktorCalculator(context, _db); return(calc.BuildStatusModel()); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest); } }
public TReportModelDto GetReportModel(TContextDto context, DateTime?startDate, DateTime?endDate, int projectID, int taskID) { try { var calculator = new TracktorCalculator(context, _db); return(Mapper.Map <TReportModelDto>(calculator.GetReport(startDate, calculator.DateOrLocalNow(endDate), projectID, taskID))); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest); } }
public TEntryDto GetEntry(TContextDto context, int entryID) { try { var calc = new TracktorCalculator(context, _db); var entry = _db.TEntries.Single(e => e.TEntryID == entryID && e.TTask.TProject.TUserID == context.TUserID); return(calc.EnrichTEntry(null, entry)); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest); } }
public TEntryDto UpdateEntry(TContextDto context, TEntryDto entry) { try { if (entry.TEntryID > 0) { var existingEntry = _db.TEntries.SingleOrDefault(e => e.TEntryID == entry.TEntryID); if (existingEntry != null) { var calculator = new TracktorCalculator(context, _db); if (existingEntry.TTask.TProject.TUserID == context.TUserID) { if (entry.IsDeleted == true) { // stop if in progress if (!existingEntry.EndDate.HasValue) { StopTask(context, entry.TTaskID); existingEntry = _db.TEntries.SingleOrDefault(e => e.TEntryID == entry.TEntryID); } _db.TEntries.Remove(existingEntry); _db.SaveChanges(); return(null); } else { var startUtc = calculator.ToUtc(entry.StartDate).Value; var endUtc = calculator.ToUtc(entry.EndDate); var now = DateTime.UtcNow; if (startUtc <= now && (!endUtc.HasValue || (endUtc.HasValue && endUtc.Value <= now && endUtc.Value > startUtc))) { existingEntry.StartDate = startUtc; existingEntry.EndDate = endUtc; _db.SaveChanges(); } } return(calculator.EnrichTEntry(null, existingEntry)); } } } return(null); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest); } }
public TEntriesModelDto GetEntriesModel(TContextDto context, DateTime?startDate, DateTime?endDate, int projectID, int startNo, int maxEntries) { try { var calc = new TracktorCalculator(context, _db); var entries = calc.GetEntries(startDate, calc.DateOrLocalNow(endDate), projectID, 0, startNo, maxEntries); return(new TEntriesModelDto { Entries = calc.CalculateEntryContribs(entries, startDate, calc.DateOrLocalNow(endDate)) }); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, HttpStatusCode.BadRequest); } }