Esempio n. 1
0
 public bool Add(Site entity)
 {
     try
     {
         var added = context.Sites.Add(entity);
         context.SaveChanges();
         return(context.Sites.Contains(added));
     }
     catch (Exception e)
     {
         _logger.Error(e, e.Message);
         return(false);
     }
 }
Esempio n. 2
0
        public string New(string Name, string Lat, string Lng)
        {
            try
            {
                string username           = User.Identity.Name;
                ApplicationDbContext cont = new ApplicationDbContext();
                var user = (from u in cont.Users
                            where u.UserName == username
                            select u).First();


                IIotContextBase icont    = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
                string          domainId = DomainSession.GetContextDomain(this.HttpContext);
                iotDomain       d        = icont.Domains.First(dm => dm.DomainName.Equals(domainId));

                Location loc = new Location();
                loc.Domain       = d;
                loc.LocationName = Name;
                loc.Lng          = double.Parse(Lng, CultureInfo.InvariantCulture);
                loc.Lat          = double.Parse(Lat, CultureInfo.InvariantCulture);
                d.Locations.Add(loc);
                icont.SaveChanges();
                return(StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Location added sucessfully.", RequestStatus.Success));
            }
            catch (Exception e)
            {
                return(StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Location add failed.", RequestStatus.Failure));
            }
        }
        public bool Add(Device entity, int LocationId, int TypeId, int SiteId)
        {
            try
            {
                Location   loc  = context.Locations.FirstOrDefault(l => l.Id == LocationId);
                DeviceType type = context.Types.FirstOrDefault(t => t.Id == TypeId);
                Site       site = context.Sites.FirstOrDefault(s => s.Id == SiteId);
                if (loc != null && type != null && entity != null && site != null)
                {
                    var endp = context.Endpoints.Add(entity.EndpInfo);
                    context.SaveChanges();
                    entity.EndpInfo = context.Endpoints.FirstOrDefault(e => e.Id == endp.Id);
                    var cred = context.Credentials.Add(entity.Credentials);
                    context.SaveChanges();
                    entity.Credentials = context.Credentials.FirstOrDefault(e => e.Id == cred.Id);

                    entity.Site           = site;
                    entity.DeviceLocation = loc;
                    entity.Type           = type;
                    var added = context.Devices.Add(entity);
                    context.SaveChanges();
                    return(context.Devices.FirstOrDefault(d => d.Id == added.Id) != null);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, e.Message);
                return(false);
            }
        }
Esempio n. 4
0
 public bool Remove(string LocationId)
 {
     try
     {
         int             LocId    = int.Parse(LocationId);
         IIotContextBase icont    = (iotContext)System.Web.HttpContext.Current.Session["iotcontext"];
         string          domainId = DomainSession.GetContextDomain(this.HttpContext);
         iotDomain       d        = icont.Domains.First(dm => dm.DomainName.Equals(domainId));
         Location        loc      = d.Locations.First(l => l.Id == LocId);
         d.Locations.Remove(loc);
         icont.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }