Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
 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);
     }
 }