Exemplo n.º 1
0
        public static bool deleteSource(Models.Source source)
        {
            bool result = false;

            try
            {
                using (var _db = new Models.BleacherDb())
                {
                    _db.MCSImports.RemoveRange(_db.MCSImports.Where(x => x.SourceId == source.Id).Select(x => x));
                    int rowsAff = _db.SaveChanges();
                    if (rowsAff > 0)
                    {
                        _db.Sources.Remove(_db.Sources.Where(x => x.Id == source.Id).Select(x => x).Take(1).FirstOrDefault());

                        _db.SaveChanges();

                        result = true;
                    }
                }
            } catch (Exception e)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(e);
            }

            return(result);
        }
Exemplo n.º 2
0
        public static bool editSource(Models.SourceCrud source)
        {
            bool result = false;

            try
            {
                using (var _db = new Models.BleacherDb())
                {
                    var sourceObj = (from x in _db.Sources where x.Id == source.Id select x).FirstOrDefault();

                    if (sourceObj != null)
                    {
                        sourceObj.Name   = source.Name;
                        sourceObj.Active = source.Active;
                        int aff = _db.SaveChanges();

                        if (aff > 0)
                        {
                            result = true;
                        }
                    }
                }
            } catch (Exception e)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(e);
            }
            return(result);
        }
Exemplo n.º 3
0
        public static async Task <Models.IndexViewModel> getImportRecords(DateTime fromdate, DateTime todate)
        {
            List <Models.FileImportview> records = null;

            Models.IndexViewModel viewObject = new Models.IndexViewModel();

            viewObject.datefrom = DateTime.Now.AddDays(-14);
            viewObject.dateto   = DateTime.Now.AddDays(1);

            using (var _db = new Models.BleacherDb())
            {
                _db.Configuration.ProxyCreationEnabled = false;
                var query = from x in _db.MCSImports
                            join s in _db.Sources on x.SourceId equals s.Id
                            select new Models.FileImportview {
                    id = x.id, LineBlob = x.LineBlob, DocNumber = (int)x.DocNumber, Location = x.Location, Timestamp = (DateTime)x.Timestamp, Source = s.Name
                };
                records = await query.ToListAsync();

                if (records != null && records.Count > 0)
                {
                    viewObject.FileImportview = records;
                }
            }
            return(viewObject);
        }
Exemplo n.º 4
0
 private static void addEvent(int sourceId, string location, int rows)
 {
     using (var _db = new Models.BleacherDb())
     {
         Models.eventLog record = new Models.eventLog();
         record.SourceId    = sourceId;
         record.Action      = "Add To Import";
         record.Description = rows.ToString() + " rows";
         record.Timestamp   = DateTime.Now;
         _db.eventLogs.Add(record);
         _db.SaveChanges();
     }
 }
Exemplo n.º 5
0
        public static async Task <List <Models.select2> > getSelectSources()
        {
            List <Models.select2> selects = new List <Models.select2>();


            using (var _db = new Models.BleacherDb())
            {
                selects = await(from x in _db.Sources select new Models.select2 {
                    id = x.Id, text = x.Name
                }).ToListAsync();
            }
            selects.Add(new Models.select2 {
                id = 0, text = "ALL"
            });

            selects = (from x in selects orderby x.id descending select x).ToList();
            return(selects);
        }
Exemplo n.º 6
0
        public static bool deleteSourceAsync(Models.Source source)
        {
            bool result = false;

            if (source.Id != 1 || source.MachineName != "UNKNOWN")
            {
                using (var _db = new Models.BleacherDb())
                {
                    deleteSourceInCache(source);

                    result = true;
                }
            }

            Task.Run(() => deleteSource(source));

            return(result);
        }
Exemplo n.º 7
0
        public static int AddLineBlobs(List <MCS.Models.MCSImport> records, int sourceId, string location)
        {
            int rowsAff = 0;

            if (records != null && records.Count() > 0)
            {
                using (var _db = new Models.BleacherDb())
                {
                    _db.MCSImports.AddRange(records);
                    rowsAff = _db.SaveChanges();
                }
                try
                {
                    addEvent(sourceId, location, rowsAff);
                } catch (Exception e)
                {
                }
            }
            return(rowsAff);
        }
Exemplo n.º 8
0
        public HttpResponseMessage Get(int SourceId)
        {
            int sourceint             = Convert.ToInt32(SourceId);
            JavaScriptSerializer jser = new JavaScriptSerializer();

            Models.sourceDocInfo docInfo  = new Models.sourceDocInfo();
            HttpResponseMessage  response = ControllerContext.Request.CreateResponse(System.Net.HttpStatusCode.Created, "true");

            if (sourceint > 0)
            {
                try
                {
                    int newDocNumber = -1;
                    using (var _db = new Models.BleacherDb())
                    {
                        var importRecord = (from x in _db.MCSImports where x.SourceId == sourceint orderby x.id descending select x).Take(1);
                        if (importRecord != null && importRecord.Count() > 0)
                        {
                            newDocNumber     = importRecord.ToArray()[0].DocNumber + 1 ?? 1;
                            docInfo.LastPath = importRecord.ToArray()[0].Location;
                        }
                        else
                        {
                            newDocNumber     = 1;
                            docInfo.LastPath = "";
                        }
                        docInfo.DocNumber = newDocNumber;
                    }
                }
                catch (Exception e)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(e);
                }
            }
            response.Content = new StringContent(jser.Serialize(docInfo));

            return(response);
        }
Exemplo n.º 9
0
        public static async Task <Models.SourceViewModel> getAllSources()
        {
            Models.SourceViewModel viewObject = new Models.SourceViewModel();

            var cachedSource = (List <Models.Source>)HttpContext.Current.Cache["FileSources." + MCS.Controllers.HomeController.cachedSessionId];

            if (cachedSource != null)
            {
                viewObject.Sources = cachedSource;
            }
            else
            {
                using (var _db = new Models.BleacherDb())
                {
                    _db.Configuration.ProxyCreationEnabled = false;
                    var query = from x in _db.Sources
                                select x;
                    viewObject.Sources = await query.ToListAsync();
                }
            }

            return(viewObject);
        }