Beispiel #1
0
        public DriverWorkstate SaveDriverWorkstate(DriverWorkstate driverWorkstate)
        {
            try
            {
                using (var hosDbContext = new HosDBContext(_connectionString))
                {
                    if (driverWorkstate.DriverWorkStateId != 0)
                    {
                        hosDbContext.DriverWorkstates.Attach(driverWorkstate);
                        hosDbContext.Entry(driverWorkstate).State = EntityState.Modified;
                    }
                    else
                    {
                        hosDbContext.DriverWorkstates.Add(driverWorkstate);
                    }

                    hosDbContext.SaveChanges();
                }
                return(driverWorkstate);
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Beispiel #2
0
        public DriverSummary SaveDriverSummary(DriverSummary driverSummary)
        {
            try
            {
                using (var hosDbContext = new HosDBContext(_connectionString))
                {
                    var tempDriverSummary =
                        hosDbContext.DriverSummaries.FirstOrDefault(
                            ds => ds.DriverId == driverSummary.DriverId && ds.WorkStateId == driverSummary.WorkStateId);

                    if (tempDriverSummary == null)
                    {
                        hosDbContext.DriverSummaries.Add(driverSummary);
                    }
                    else
                    {
                        tempDriverSummary.TotalSeconds = driverSummary.TotalSeconds;
                    }

                    hosDbContext.SaveChanges();
                }
                return(driverSummary);
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }