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 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.º 3
0
        private static bool deleteSourceInCache(Models.Source source)
        {
            bool result = false;

            try
            {
                List <Models.Source> cacheSources = (List <Models.Source>)HttpRuntime.Cache["FileSources." + MCS.Controllers.HomeController.cachedSessionId];

                if (cacheSources != null)
                {
                    cacheSources.Remove(cacheSources.Where(x => x.Id == source.Id).Select(x => x).FirstOrDefault());

                    HttpRuntime.Cache.Insert("FileSources." + MCS.Controllers.HomeController.cachedSessionId, cacheSources, null, DateTime.Now.AddDays(4), System.Web.Caching.Cache.NoSlidingExpiration);
                }
            } catch (Exception e)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(e);
            }
            return(result);
        }
Exemplo n.º 4
0
        public ActionResult editSources()
        {
            System.Collections.Specialized.NameValueCollection RequestParams = ControllerContext.RequestContext.HttpContext.Request.Params;

            bool result = false;

            if (RequestParams.Count > 0)
            {
                Helpers.jqGrid <Models.SourceCrud> jqgrid = new Helpers.jqGrid <Models.SourceCrud>();

                Models.SourceCrud crudVars = jqgrid.getReqParamsAsObject(RequestParams);

                if (crudVars == null)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                Models.Source rowToEdit = Helpers.SourcesAdapter.getcachedRow(crudVars.Id, cachedSessionId);

                if (rowToEdit != null && crudVars.oper != null)
                {
                    if (crudVars.oper == "edit")
                    {
                        if (Helpers.SourcesAdapter.editSource(crudVars))
                        {
                            result = false;
                            Helpers.SourcesAdapter.editcachedRow(crudVars, cachedSessionId);
                        }
                    }
                    else if (crudVars.oper == "del")
                    {
                        if (Helpers.SourcesAdapter.deleteSourceAsync(rowToEdit))
                        {
                            result = true;
                        }
                    }
                }
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        public static Models.Source getcachedRow(int rowId, string sessionid)
        {
            List <Models.Source> sources = new List <Models.Source>();

            Models.Source row = null;

            try
            {
                sources = (List <Models.Source>)HttpRuntime.Cache["FileSources." + sessionid];

                if (sources != null && sources.Count > 0)
                {
                    row = sources[rowId - 1];
                }
            } catch (Exception e)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(e);
            }

            return(row);
        }
Exemplo n.º 6
0
        public async Task <Models.Source> getSourceId()
        {
            int        sourceId   = 1;
            HttpClient httpclient = new HttpClient();

            Models.Source record = new Models.Source()
            {
                MachineName = Environment.MachineName, Name = Environment.MachineName, IPAddress = GetLocalIPAddress()
            };

            if (record != null)
            {
                setAuthorizationHeader(httpclient);

                httpclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));

                string Content = jser.Serialize(record);

                var obj = await httpclient.PostAsJsonAsync("http://localhost:60521/api/Sources", Content)
                          .ConfigureAwait(continueOnCapturedContext: false);

                var returnval = obj.Content.ReadAsStringAsync().Result;

                if (returnval != null && returnval.Length > 0)
                {
                    try
                    {
                        record.Id = Convert.ToInt32(returnval);
                    }
                    catch (Exception e)
                    {
                        record.Id = 1;
                    }
                }
            }

            return(record);
        }
Exemplo n.º 7
0
 void IEntitySecurity <Models.Source> .ValidateUpdate(Models.Source entity, Models.Source value)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
 void IEntitySecurity <Models.Source> .ValidateRead(Models.Source value, string expand)
 {
     //CheckSuper();
 }
Exemplo n.º 9
0
 private void OpenContextMenu(Models.Source room)
 {
     IsShowingSelectRoomModal = true;
     CurrentSelectedSource    = room;
 }