private StateResponse _putStop(dialogTimeEntities db, string persId, StartStop entry, DateTime datum, bool manuell = false)
        {
            if (entry == null)
            {
                return(new Models.StateResponse()
                {
                    Success = false,
                    Error = "Kann man nicht stoppen wenn nicht gestarted. Bitte melden!"
                });
            }
            var timeIntervall = entry.TimeIntervall;

            if (timeIntervall.EndsWith("-") || timeIntervall.EndsWith("p"))
            {
                if (timeIntervall.EndsWith("-"))
                {
                    entry.TimeIntervall = timeIntervall + string.Format("{0:00}:{1:00}", datum.Hour, datum.Minute);
                }
                else
                {
                    entry.TimeIntervall = timeIntervall.Substring(0, timeIntervall.Length - 1);
                }
                if (manuell)
                {
                    entry.StartStopManuell = manuell;
                }
                var ii = new Intervalls(entry.TimeIntervall);
                var jj = new Intervalls();
                var q2 = from x in db.RapportEintraege
                         where x.PersId == persId && x.Datum == datum.Date
                         select x;
                foreach (var e in q2)
                {
                    jj.AddRange(new Intervalls(e.TimeIntervall));
                }
                ii.CutWith(jj);
                var eintrag = new RapportEintrag()
                {
                    Id                   = Guid.NewGuid(),
                    AnsatzExtern         = 0,
                    AnsatzIntern         = 0,
                    ArbeitsRapportNr     = 0,
                    Aufwand              = Math.Round(ii.EllapsedAsDouble, 1),
                    Datum                = datum.Date,
                    ErfDatum             = DateTime.Now,
                    ErfName              = persId,
                    LohnkategorieKuerzel = entry.LohnkategorieKuerzel,
                    LohnKatKontierung    = "",
                    MandantId            = Guid.Parse("331A58AF-C3F6-42BE-BF55-0AE0C5F26C87"),
                    MutDatum             = DateTime.Now,
                    MutName              = persId,
                    PersId               = persId,
                    ProjektId            = entry.ProjektId,
                    TarifkategorieId     = entry.TarifkategorieId,
                    Text                 = entry.Text,
                    TimeIntervall        = ii.ToString(),
                    Verrechnet           = 0,
                    Zuschlag             = 0,
                    StartStopManuell     = entry.StartStopManuell
                };
                db.RapportEintraege.Add(eintrag);
                db.SaveChanges();
                return(new Models.StateResponse()
                {
                    Success = true,
                    TimeIntervall = eintrag.TimeIntervall,
                    Error = null
                });
            }
            else
            {
                return(new Models.StateResponse()
                {
                    Success = false,
                    Error = "Kann man nicht stoppen wenn nicht gestarted. Bitte melden!"
                });
            }
        }
Exemple #2
0
        private void BaseStopAction(DateTime time)
        {
            GotoState(InitState.NotRunningLogged);
            var entities = new DialogTimeEntities();

            using (entities)
            {
                var q = from x in entities.StartStops
                        where (x.TimeIntervall.EndsWith("-") || x.TimeIntervall.EndsWith("p")) && x.PersId == _user.PersId
                        select x;
                if (q.Any())
                {
                    if (q.Count() > 1)
                    {
                        // TODO: Szenario behandeln
                        // I'm stopping, but there are many pending activities
                        return;
                    }
                    var first = q.First();
                    if (first.TimeIntervall.EndsWith("p"))
                    {
                        first.TimeIntervall = first.TimeIntervall.Substring(0, first.TimeIntervall.Length - 1);
                    }
                    else
                    {
                        first.TimeIntervall += string.Format("{0:00}:{1:00}", time.Hour, time.Minute);
                    }
                    var ii = new Intervalls(first.TimeIntervall);
                    var jj = new Intervalls();
                    var q2 = from x in entities.RapportEintraeges
                             where x.PersId == _user.PersId && x.Datum == time
                             select x;
                    foreach (var e in q2)
                    {
                        jj.AddRange(new Intervalls(e.TimeIntervall));
                    }
                    ii.CutWith(jj);
                    RapportEintraege eintrag = new RapportEintraege()
                    {
                        Id                   = Guid.NewGuid(),
                        AnsatzExtern         = 0,
                        AnsatzIntern         = 0,
                        ArbeitsRapportNr     = 0,
                        Aufwand              = Math.Round(ii.EllapsedAsDouble, 1),
                        Datum                = time,
                        ErfDatum             = DateTime.Now,
                        ErfName              = _user.PersId,
                        LohnkategorieKuerzel = first.LohnkategorieKuerzel,
                        LohnKatKontierung    = "",
                        MandantId            = Guid.Parse("331A58AF-C3F6-42BE-BF55-0AE0C5F26C87"),
                        MutDatum             = DateTime.Now,
                        MutName              = _user.PersId,
                        PersId               = _user.PersId,
                        ProjektId            = first.ProjektId,
                        TarifkategorieId     = first.TarifkategorieId,
                        Text                 = first.Text,
                        TimeIntervall        = ii.ToString(),
                        Verrechnet           = 0,
                        Zuschlag             = 0
                    };
                    entities.RapportEintraeges.Add(eintrag);
                    entities.SaveChanges();
                    _intervalls = new Helpers.Intervalls(first.TimeIntervall);
                    _timer_Elapsed(this, null);
                    GotoState(InitState.NotRunningLogged);
                }
            }
        }