public int UpdateMachineSession(MachineSession model)
        {
            int machineSessionId = 0;

            try
            {
                using (var db = new DBContext())
                {
                    if (ModelState.IsValid)
                    {
                        if (model.MachineSessionId > 0)
                        {
                            MachineSession machineSession = db.MachineSessions.Where(x => x.MachineSessionId == model.MachineSessionId).FirstOrDefault();
                            if (machineSession != null)
                            {
                                machineSession.SessionEnd      = model.SessionEnd;
                                machineSession.ModifiedDate    = DateTime.Now;
                                db.Entry(machineSession).State = EntityState.Modified;
                                db.SaveChanges();
                                machineSessionId = machineSession.MachineSessionId;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionHandler handler = new ExceptionHandler();
                handler.HandleException(e);
            }

            return(machineSessionId);
        }
        public int AddMachineSession(MachineSession model)
        {
            int machineSessionId = 0;

            try
            {
                using (var db = new DBContext())
                {
                    if (ModelState.IsValid)
                    {
                        model.CreatedDate = DateTime.Now;
                        db.MachineSessions.Add(model);
                        db.SaveChanges();
                        machineSessionId = model.MachineSessionId;
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionHandler handler = new ExceptionHandler();
                handler.HandleException(e);
            }

            return(machineSessionId);
        }