Пример #1
0
        public static int AddSource(string responseContent)
        {
            int SourceId = -1;

            try
            {
                MCS.Models.Source newRecord = json.Deserialize <MCS.Models.Source>(responseContent);

                if (newRecord != null)
                {
                    using (var _db = new MCS.Models.BleacherDb())
                    {
                        List <MCS.Models.Source> currerntMachine = (from x in _db.Sources where x.MachineName == newRecord.MachineName select x).ToList();

                        if (currerntMachine.Count == 0)
                        {
                            newRecord.Active = true;
                            _db.Sources.Add(newRecord);
                            _db.SaveChanges();
                            SourceId = newRecord.Id;
                        }
                        else
                        {
                            SourceId = currerntMachine[0].Id;
                        }
                    }
                }
            } catch (Exception e)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(e);
            }

            return(SourceId);
        }
Пример #2
0
        public static int getSourceId(String MachineName)
        {
            int sourceId = -1;

            try
            {
                using (var _db = new MCS.Models.BleacherDb())
                {
                    var SourceId = (from x in _db.Sources where x.MachineName == MachineName.Trim() select x.Id).ToArray();
                    if (SourceId != null && SourceId.Length > 0)
                    {
                        sourceId = SourceId[0];
                    }
                }
            } catch (Exception e)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(e);
            }

            return(sourceId);
        }