public StateResponse PutStateEx(string name, [FromBody] PutStateInfoEx data) { StartStop entry = null; var db = new dialogTimeEntities(); using (db) { try { var q = from x in db.StartStops where x.PersId == name orderby x.Id descending select x; if (q.Any()) { entry = q.First(); } // --------------------------------------------- switch (data.Action) { case "start": return(_putStart(db, name, entry, data, true)); case "stop": return(_putStop(db, name, entry, data.Datum, true)); default: return(new Models.StateResponse() { Success = false, Error = "Keine Aktion vorhanden. Bitte melden!" }); } } catch (Exception ex) { return(new Models.StateResponse() { Success = false, Error = ex.Message }); } } }
private StateResponse _putStart(dialogTimeEntities db, string persId, StartStop entry, PutStateInfoEx data, bool manuell = false) { if (entry != null && (entry.TimeIntervall.EndsWith("-") || entry.TimeIntervall.EndsWith("p"))) { return(new StateResponse() { Success = false, Error = "Kann man nicht starten wenn nicht gestoppt. Bitte melden!" }); } else { var x = new StartStop() { Datum = data.Datum.Date, LohnkategorieKuerzel = data.LohnKategorie, PersId = persId, ProjektId = Guid.Parse(data.Projekt), TarifkategorieId = data.TarifKategorie, Text = data.Text, TimeIntervall = string.Format("{0:00}:{1:00}-", data.Datum.Hour, data.Datum.Minute), StartStopManuell = manuell }; db.StartStops.Add(x); db.SaveChanges(); return(new Models.StateResponse() { Success = true, TimeIntervall = x.TimeIntervall, Error = null }); } }