Ejemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="lstMac"></param>
 /// <param name="SiteName"></param>
 /// <returns></returns>
 public bool RegisterListOfMacAddresses(RequestLocationDataVM model)
 {
     try
     {
         foreach (var mac in model.MacAddresses)
         {
             //If MacAddress already exist with None status then
             if (db.Device.Any(m => m.MacAddress == mac))
             {
                 var objMac = db.Device.FirstOrDefault(m => m.MacAddress == mac);
                 //db.Entry(objMac).State = System.Data.Entity.EntityState.Modified;
                 //db.SaveChanges();
                 UpdateStatusToRegister(objMac.DeviceId);
             }
             else
             {
                 Device objMac = new Device();
                 objMac.MacAddress = mac;
                 //objMa = DeviceStatus.Registered;
                 //objMac.RtlsConfigureId = model.RtlsConfigurationId;
                 //objMac.IsCreatedByAdmin = true;
                 db.Device.Add(objMac);
                 db.SaveChanges();
                 UpdateStatusToRegister(objMac.DeviceId);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(true);
 }
Ejemplo n.º 2
0
        public HttpResponseMessage Delete(RequestLocationDataVM model)
        {
            Result objResult = new Result();
            string retResult = "";

            try
            {
                this.log.Debug("Enter into the DeleteMacAddress Action Method");
                foreach (var item in model.MacAddresses)
                {
                    var deviceObject = db.MacAddress.FirstOrDefault(m => m.Mac == item);
                    if (deviceObject.Intstatus != Convert.ToInt32(DeviceStatus.Registered))
                    {
                        db.MacAddress.Remove(deviceObject);
                        db.SaveChanges();
                        retResult = string.Format("{0} Successfully Deleted from server", item);
                    }
                    else
                    {
                        retResult = string.Format("{0} is a Registered User So shouldn't Delete", item);
                    }
                }
            }
            catch (Exception ex)
            {
                this.log.Error("Exception occur" + ex.InnerException.Message);
                retResult            = "Exception occur" + ex.InnerException.Message;
                objResult.returncode = -1;
            }
            objResult.errmsg = retResult;
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(retResult))
            });
        }
Ejemplo n.º 3
0
        public async Task <HttpResponseMessage> DeRegisterDevices(RequestLocationDataVM model)
        {
            Notification objNotifications = new Notification();

            try
            {
                HttpRequestMessage message = new HttpRequestMessage(new HttpMethod("DELETE"), "/api/engage/v1/device_monitors/");
                var queryParams            = new Dictionary <string, string>()
                {
                    { "sn", ConfigurationManager.AppSettings["sn"] },
                    { "bn", ConfigurationManager.AppSettings["bn"] },
                    { "device_ids", String.Join(",", model.MacAddresses) }
                };

                message.Content = new FormUrlEncodedContent(queryParams);
                try
                {
                    HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(message);

                    if (httpResponseMessage.EnsureSuccessStatusCode().IsSuccessStatusCode)
                    {
                        string resultContent = await httpResponseMessage.Content.ReadAsStringAsync();

                        objNotifications = JsonConvert.DeserializeObject <Notification>(resultContent);
                        if (objNotifications.result.returncode == Convert.ToInt32(FatiApiResult.Success))
                        {
                            using (MacAddressRepository objMacRepository = new MacAddressRepository())
                            {
                                objMacRepository.DeRegisterListOfMacs(model.MacAddresses);
                            }
                        }
                    }
                    else
                    {
                        objNotifications.result.returncode = Convert.ToInt32(httpResponseMessage.StatusCode.ToString());
                        objNotifications.result.errmsg     = "Some Problem Occured";
                    }
                }
                catch (Exception ex)
                {
                    string errorType    = ex.GetType().ToString();
                    string errorMessage = errorType + ": " + ex.Message;
                    throw new Exception(errorMessage, ex.InnerException);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.InnerException.Message);
                objNotifications.result.returncode = -1;
                objNotifications.result.errmsg     = ex.InnerException.Message;
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 4
0
        public async Task <HttpResponseMessage> GetDevices(RequestLocationDataVM model)
        {
            MonitorDevices objMonitorDevice = new MonitorDevices();

            //Notification objNotifications = new Notification();
            using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository())
            {
                Site objSite = objRtlsConfigurationRepository.GetAsPerSite(model.SiteId, model.SiteName);
                CommonHeaderInitializeHttpClient(objSite.RtlsConfiguration.EngageBaseAddressUri);

                ////Check the Parameter search or not,if it then add in the QueryParams,else keep as it is
                queryParams = new FormUrlEncodedContent(new Dictionary <string, string>()
                {
                    { "sn", objSite.RtlsConfiguration.EngageSiteName },
                    { "bn", objSite.RtlsConfiguration.EngageBuildingName }
                    //,
                    //{"device_ids",String.Join(",",model.MacAddresses) }
                }).ReadAsStringAsync().Result;

                try
                {
                    //var result = await httpClient.GetAsync(completeFatiAPI, new StringContent(queryParams, Encoding.UTF8, "application/x-www-form-urlencoded"));
                    var result = await httpClient.GetAsync(completeFatiAPI);

                    if (result.IsSuccessStatusCode)
                    {
                        String msg = "";

                        string resultContent = await result.Content.ReadAsStringAsync();

                        objMonitorDevice = JsonConvert.DeserializeObject <MonitorDevices>(resultContent);
                        using (MacAddressRepository objMacRepo = new MacAddressRepository())
                        {
                            msg = objMacRepo.CheckDeviceRegisted(objMonitorDevice, model.SiteId);
                        }
                        objMonitorDevice.result.errmsg = msg;
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                }
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objMonitorDevice), Encoding.UTF8, "application/json")
                          //Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="SiteId"></param>
        /// <param name="Mac"></param>
        /// <returns></returns>
        public bool SaveMacAddress(RequestLocationDataVM model)
        {
            try
            {
                Device objDevice = new Device();
                DeviceAssociateSite objDeviceAssociate = new DeviceAssociateSite();
                foreach (var MacAddress in model.MacAddresses)
                {
                    //If MacAddress not exist in the whole system create the new one and associate with Site
                    if (!(db.Device.Any(m => m.MacAddress == MacAddress)))
                    {
                        objDevice.MacAddress = MacAddress;
                        db.Device.Add(objDevice);
                        db.SaveChanges();
                    }
                    else
                    {
                        objDevice = db.Device.FirstOrDefault(m => m.MacAddress == MacAddress);
                    }

                    if (!(db.DeviceAssociateSite.Any(m => m.Device.MacAddress == MacAddress && m.SiteId == model.SiteId)))
                    {
                        objDeviceAssociate.SiteId                       = model.SiteId;
                        objDeviceAssociate.DeviceId                     = objDevice.DeviceId;
                        objDeviceAssociate.CreatedDateTime              = DateTime.Now;
                        objDeviceAssociate.IsCreatedByAdmin             = true;
                        objDeviceAssociate.DeviceRegisteredInEngineType = (DeviceRegisteredInEngine)model.RtlsEngineType;
                        //objDeviceAssociate.RtlsConfigureId = model.RtlsConfigurationId;
                        //objDeviceAssociate.IsCreatedByAdmin = true;
                        db.DeviceAssociateSite.Add(objDeviceAssociate);
                    }
                    else
                    {
                        objDeviceAssociate = db.DeviceAssociateSite.FirstOrDefault(m => m.Device.MacAddress == MacAddress && m.SiteId == model.SiteId);
                        objDeviceAssociate.DeviceRegisteredInEngineType = (DeviceRegisteredInEngine)model.RtlsEngineType;
                        objDeviceAssociate.CreatedDateTime  = DateTime.Now;
                        objDeviceAssociate.IsCreatedByAdmin = true;
                        db.Entry(objDeviceAssociate).State  = EntityState.Modified;
                    }
                    db.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 6
0
 public HttpResponseMessage Save(RequestLocationDataVM model)
 {
     try
     {
         using (MacAddressRepository objMacRepository = new MacAddressRepository())
         {
             if (objMacRepository.CheckListExistOrNot(model.MacAddresses))
             {
                 objMacRepository.SaveMacAddress(model.MacAddresses, true);
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex.Message);
     }
     return(Request.CreateResponse(HttpStatusCode.OK));
 }
Ejemplo n.º 7
0
        public HttpResponseMessage GetListOfMacAddress(RequestLocationDataVM model)
        {
            IEnumerable Maclist = null;

            try
            {
                if (db.RtlsConfiguration.Any(m => m.SiteId == model.SiteId))
                {
                    Maclist = db.DeviceAssociateSite.Where(m => m.Site.SiteId == model.SiteId).Select(m => new { Id = m.Id, Mac = m.Device.MacAddress, StrStatus = m.status.ToString(), IsEntryNotify = m.IsEntryNotify, IsTrackByAdmin = m.IsTrackByAdmin, IsDisplay = m.IsTrackByRtls, m.IsCreatedByAdmin }).ToList(); // IsDIsplay =m.IsDeviceRegisterInRtls
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.InnerException.Message);
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(Maclist), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 8
0
        public HttpResponseMessage UpdateIsDisplay(RequestLocationDataVM model)
        {
            string retResult = "";

            try
            {
                if (db.MacAddress.Any(m => m.Mac == model.Mac))
                {
                    var ObjMac = db.MacAddress.First(m => m.Mac == model.Mac);
                    ObjMac.IsDisplay       = model.IsDisplay;
                    db.Entry(ObjMac).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                this.log.Error("Exception occur" + ex.InnerException.Message);
                retResult = "Exception occur" + ex.InnerException.Message;
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 9
0
        public HttpResponseMessage UpdateTrackByAdmin(RequestLocationDataVM model)
        {
            string retResult = "";

            try
            {
                if (db.Device.Any(m => m.MacAddress == model.Mac))
                {
                    var ObjMac = db.DeviceAssociateSite.First(m => m.Device.MacAddress == model.Mac && m.SiteId == model.SiteId);
                    ObjMac.IsTrackByAdmin  = model.IsTrackByAdmin;
                    db.Entry(ObjMac).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                this.log.Error("Exception occur" + ex.InnerException.Message);
                retResult = "Exception occur" + ex.InnerException.Message;
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 10
0
        public async Task <HttpResponseMessage> AddDevices(RequestLocationDataVM model)
        {
            Notification objNotifications = new Notification();

            try
            {
                queryParams = new FormUrlEncodedContent(new Dictionary <string, string>()
                {
                    { "sn", /*model.CompanyName*/ ConfigurationManager.AppSettings["sn"] },
                    { "bn", /* model.SiteName*/ ConfigurationManager.AppSettings["bn"] },
                    { "device_ids", String.Join(",", model.MacAddresses) }
                }).ReadAsStringAsync().Result;

                var result = await httpClient.PostAsync(completeFatiAPI, new StringContent(queryParams, Encoding.UTF8, "application/x-www-form-urlencoded"));

                if (result.IsSuccessStatusCode)
                {
                    string resultContent = await result.Content.ReadAsStringAsync();

                    objNotifications = JsonConvert.DeserializeObject <Notification>(resultContent);
                    if (objNotifications.result.returncode == Convert.ToInt32(FatiApiResult.Success))
                    {
                        using (MacAddressRepository objMacRepository = new MacAddressRepository())
                        {
                            objMacRepository.RegisterListOfMacAddresses(model.MacAddresses, model.IscreatedByAdmin);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.InnerException.Message);
                objNotifications.result.returncode = -1;
                objNotifications.result.errmsg     = ex.InnerException.Message;
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 11
0
        public HttpResponseMessage Delete(RequestLocationDataVM model)
        {
            Result objResult = new Result();
            string retResult = "";

            try
            {
                this.log.Debug("Enter into the DeleteMacAddress Action Method");
                foreach (var item in model.MacAddresses)
                {
                    DeviceAssociateSite deviceAssociateObject = db.DeviceAssociateSite.FirstOrDefault(m => m.Device.MacAddress == item && m.SiteId == model.SiteId);
                    if (deviceAssociateObject.status != DeviceStatus.Registered)
                    {
                        db.DeviceAssociateSite.Remove(deviceAssociateObject);
                        db.SaveChanges();
                        retResult += item + " Successfully Deleted from server. " + Environment.NewLine;
                    }
                    else
                    {
                        retResult += item + " is a Registered User so shouldn't Delete. " + Environment.NewLine;
                    }
                }
            }
            catch (Exception ex)
            {
                this.log.Error("Exception occur" + ex.InnerException.Message);
                retResult            = "Exception occur" + ex.InnerException.Message;
                objResult.returncode = -1;
            }

            objResult.errmsg = retResult;
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objResult), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 12
0
        public async Task <HttpResponseMessage> AddDevices(RequestLocationDataVM model)
        {
            Notification        objNotifications = new Notification();
            DeviceAssociateSite deviceid         = null;

            using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository())
            {
                Site objSite = objRtlsConfigurationRepository.GetAsPerSite(model.SiteId);

                foreach (var item in model.MacAddresses)
                {
                    // When Device is coming for reregister in OmniEngiene
                    int deviceId = _OmniDeviceMappingRepository.GetDeviceId(item);
                    deviceid = objRtlsConfigurationRepository.DeviceAssociateSiteStatus(deviceId);
                    if (deviceid.status == DeviceStatus.DeRegistered)
                    {
                        OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness();
                        RequestOmniModel   objRequestOmniModel   = new RequestOmniModel();
                        objRequestOmniModel.MacAddress = item;
                        await objOmniEngineBusiness.ReRegister(objRequestOmniModel);
                    }
                }
                //First time devive will store
                if (deviceid.status == DeviceStatus.None)
                {
                    try
                    {
                        if (objSite.RtlsConfiguration.RtlsEngineType == RtlsEngine.OmniEngine)
                        {
                            foreach (var item in model.MacAddresses)
                            {
                                OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness();
                                RequestOmniModel   objRequestOmniModel   = new RequestOmniModel();
                                objRequestOmniModel.MacAddress = item;

                                await objOmniEngineBusiness.regMacToOmniEngine(objRequestOmniModel);

                                objNotifications.result.returncode = Convert.ToInt32(FatiApiResult.Success);
                                using (MacAddressRepository objMacRepository = new MacAddressRepository())
                                {
                                    objMacRepository.RegisterListOfMacAddresses(model);
                                }
                            }
                        }
                        if (objSite.RtlsConfiguration.RtlsEngineType == RtlsEngine.EngageEngine)
                        {
                            foreach (var item in model.MacAddresses)
                            {
                                EngageEngineBusiness objEngageEngineBusiness = new EngageEngineBusiness();
                                RequestOmniModel     objRequestOmniModel     = new RequestOmniModel();
                                objRequestOmniModel.SiteId     = model.SiteId;
                                objRequestOmniModel.MacAddress = item;
                                if (await objEngageEngineBusiness.regMacToEngageEngine(objRequestOmniModel))
                                {
                                    objNotifications.result.returncode = Convert.ToInt32(FatiApiResult.Success);
                                    using (MacAddressRepository objMacRepository = new MacAddressRepository())
                                    {
                                        objMacRepository.RegisterListOfMacAddresses(model);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex.InnerException.Message);
                        objNotifications.result.returncode = -1;
                        objNotifications.result.errmsg     = ex.InnerException.Message;
                    }
                }
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 13
0
        public async Task <HttpResponseMessage> DeleteDevices(RequestLocationDataVM model)
        {
            Notification        objNotifications = new Notification();
            DeviceAssociateSite deviceStatus     = null;

            using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository())
            {
                Site objSite = objRtlsConfigurationRepository.GetAsPerSite(model.SiteId);

                foreach (var item in model.MacAddresses)
                {
                    // When Device is coming to delete in OmniEngiene
                    int deviceId = _OmniDeviceMappingRepository.GetDeviceId(item);
                    deviceStatus = objRtlsConfigurationRepository.DeviceAssociateSiteStatus(deviceId);
                    if (deviceStatus.status == DeviceStatus.DeRegistered)
                    {
                        OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness();
                        RequestOmniModel   objRequestOmniModel   = new RequestOmniModel();
                        objRequestOmniModel.MacAddress = item;
                        var returnStatus = await objOmniEngineBusiness.DeleteDevices(objRequestOmniModel);

                        if (returnStatus == true)
                        {
                            try
                            {
                                //Delete Device ralated data
                                DeviceAssociateSite _DeviceAssociateSite = db.DeviceAssociateSite.FirstOrDefault(k => k.DeviceId == deviceId);
                                Device            _Device            = db.Device.FirstOrDefault(p => p.DeviceId == deviceId);
                                NetWorkOfSite     _NetworkOfSite     = db.NetWorkOfSite.Where(p => p.SiteId == model.SiteId).Where(q => q.LocServiceTypeId != 0).FirstOrDefault();
                                OmniDeviceMapping _OmniDeviceMapping = db.OmniDeviceMapping.FirstOrDefault(k => k.DeviceId == deviceId);

                                //If User registered from CaptivePortal
                                if (_DeviceAssociateSite.IsRegisterInCaptivePortal == true)
                                {
                                    WifiUserLoginCredential _WifiUserLoginCredential = db.WifiUserLoginCredential.Where(p => p.Device.DeviceId == deviceId).Where(q => q.NetWorkOfSiteId == _NetworkOfSite.NetWorkOfSiteId).FirstOrDefault();
                                    WifiUser     _WifiUser     = db.WifiUser.Where(p => p.UserId == _WifiUserLoginCredential.WifiUserId).FirstOrDefault();
                                    UsersAddress _UsersAddress = db.UsersAddress.Where(p => p.UserId == _WifiUser.UserId).FirstOrDefault();
                                    db.UsersAddress.Remove(_UsersAddress);
                                    db.WifiUser.Remove(_WifiUser);
                                    db.WifiUserLoginCredential.Remove(_WifiUserLoginCredential);
                                }


                                db.DeviceAssociateSite.Remove(_DeviceAssociateSite);
                                db.OmniDeviceMapping.Remove(_OmniDeviceMapping);
                                db.Device.Remove(_Device);
                                db.SaveChanges();
                            }
                            catch (Exception ex)
                            {
                                log.Error(ex.Message);
                            }
                        }
                    }
                }
            }

            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 14
0
        public async Task <HttpResponseMessage> DeRegisterDevices(RequestLocationDataVM model)
        {
            Notification       objNotifications      = new Notification();
            HttpRequestMessage message               = new HttpRequestMessage();
            OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness();
            RequestOmniModel   objRequestOmniModel   = new RequestOmniModel();

            try
            {
                using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository())
                {
                    Site objSite = objRtlsConfigurationRepository.GetAsPerSite(model.SiteId, model.SiteName);
                    if (objSite.RtlsConfiguration.RtlsEngineType == RtlsEngine.OmniEngine)
                    {
                        foreach (var item in model.MacAddresses)
                        {
                            objRequestOmniModel.MacAddress = item;
                            var deregisterData = await objOmniEngineBusiness.DeregisterMacFromOmniEngine(objRequestOmniModel);
                        }
                    }
                    else if (objSite.RtlsConfiguration.RtlsEngineType == RtlsEngine.EngageEngine)
                    {
                        CommonHeaderInitializeHttpClient(objSite.RtlsConfiguration.EngageBaseAddressUri);
                        message = new HttpRequestMessage(new HttpMethod("DELETE"), "/api/engage/v1/device_monitors/");
                        var queryParams = new Dictionary <string, string>()
                        {
                            { "sn", objSite.RtlsConfiguration.EngageSiteName },
                            { "bn", objSite.RtlsConfiguration.EngageBuildingName },
                            { "device_ids", String.Join(",", model.MacAddresses) }
                        };

                        message.Content = new FormUrlEncodedContent(queryParams);
                        try
                        {
                            HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(message);

                            if (httpResponseMessage.EnsureSuccessStatusCode().IsSuccessStatusCode)
                            {
                                string resultContent = await httpResponseMessage.Content.ReadAsStringAsync();

                                objNotifications = JsonConvert.DeserializeObject <Notification>(resultContent);
                                if (objNotifications.result.returncode == Convert.ToInt32(FatiApiResult.Success))
                                {
                                    using (MacAddressRepository objMacRepository = new MacAddressRepository())
                                    {
                                        objMacRepository.DeRegisterListOfMacs(model.MacAddresses);
                                    }
                                }
                            }
                            else
                            {
                                objNotifications.result.returncode = Convert.ToInt32(httpResponseMessage.StatusCode.ToString());
                                objNotifications.result.errmsg     = "Some Problem Occured";
                            }
                        }
                        catch (Exception ex)
                        {
                            string errorType    = ex.GetType().ToString();
                            string errorMessage = errorType + ": " + ex.Message;
                            throw new Exception(errorMessage, ex.InnerException);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.InnerException.Message);
                objNotifications.result.returncode = -1;
                objNotifications.result.errmsg     = ex.InnerException.Message;
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 15
0
        public async Task <HttpResponseMessage> StartNotification(NotificationRequest model)
        {
            Notification objNotifications = new Notification();


            try {
                #region Save ResetTime in RtlsConfiguration

                if (model.NotificationType != null && model.ResetTime > 0)
                {
                    //save notification Reset Time
                    RtlsConfiguration objrtls = objRtlsConfigurationRepository.GetAsPerSiteId(model.SiteId);
                    if (objrtls != null)
                    {
                        if (model.NotificationType == NotificationType.Entry)
                        {
                            objrtls.AreaNotification = model.ResetTime;
                        }
                        if (model.NotificationType == NotificationType.Approach)
                        {
                            objrtls.ApproachNotification = model.ResetTime;
                        }
                        objRtlsConfigurationRepository.SaveAndUpdateAsPerSite(objrtls);
                    }
                }
                #endregion

                #region Save Notification Type in DeviceAssociateSite
                if (model.NotificationType != null && model.MacAddressList != null && model.MacAddressList.Length > 0)
                {
                    using (ApplicationDbContext db = new ApplicationDbContext())
                    {
                        foreach (var mac in model.MacAddressList)
                        {
                            if (db.Device.Any(m => m.MacAddress == mac))
                            {
                                var ObjMacNotify = db.DeviceAssociateSite.First(m => m.Device.MacAddress == mac && m.SiteId == model.SiteId);
                                if (model.NotificationType == NotificationType.Entry)
                                {
                                    ObjMacNotify.IsTrackByAdmin = true;
                                }
                                else if (model.NotificationType == NotificationType.Approach)
                                {
                                    ObjMacNotify.IsEntryNotify = true;
                                }
                                else if (model.NotificationType == NotificationType.All)
                                {
                                    ObjMacNotify.IsTrackByAdmin = true; ObjMacNotify.IsEntryNotify = true;
                                }
                                db.Entry(ObjMacNotify).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                        }
                    }
                }
                #endregion

                #region Save Area in RtlsArea
                if (model.AreaID != null && model.AreaID.Length > 0)
                {
                    //RtlsConfiguration objrtls = objRtlsConfigurationRepository.GetAsPerSiteId(model.SiteId);
                    List <RtlsArea> arealist = new List <RtlsArea>();
                    foreach (var area in model.AreaID)
                    {
                        RtlsArea a = new RtlsArea();
                        a.GeoFencedAreas      = area;
                        a.RtlsConfigurationId = model.SiteId;
                        arealist.Add(a);
                    }
                    if (arealist.Count > 0)
                    {
                        using (RtlsAreaApiRepository rtlsRepo = new RtlsAreaApiRepository())
                        {
                            rtlsRepo.RemoveAreaAsPerSite(model.SiteId);
                            rtlsRepo.SaveAndUpdateAsPerSite(arealist);
                        }
                    }
                }
                #endregion

                #region Register MAC Address to RTLS
                if (model.MacAddressList.Length > 0)
                {
                    RequestLocationDataVM rldvm = new RequestLocationDataVM();
                    rldvm.SiteId = model.SiteId;
                    string[] RegisteredMacAdress; List <string> lstDeviceToRegister = new List <string>();
                    using (MacAddressRepository macRepo = new MacAddressRepository())
                    {
                        RegisteredMacAdress = macRepo.GetMacByStatus(DeviceStatus.Registered);
                    }
                    if (RegisteredMacAdress != null & RegisteredMacAdress.Length > 0)
                    {
                        foreach (var mac in model.MacAddressList)
                        {
                            if (!RegisteredMacAdress.Contains(mac))
                            {
                                lstDeviceToRegister.Add(mac);
                            }
                        }
                    }
                    else
                    {
                        lstDeviceToRegister.AddRange(model.MacAddressList);
                    }

                    rldvm.SiteName     = "";
                    rldvm.MacAddresses = lstDeviceToRegister.ToArray();
                    try
                    {
                        await AddDevices(rldvm);
                    }
                    catch
                    {
                        //TODO Possible duplicate mac address error.
                    }
                }
                #endregion

                objNotifications.result.returncode = 0;
                objNotifications.result.errmsg     = "";
            }
            catch (Exception e)
            {
                objNotifications.result.returncode = -1;
                objNotifications.result.errmsg     = e.Message;
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 16
0
        public async Task <HttpResponseMessage> UserNotification(NotificationRequest model)
        {
            Notification objNotifications = new Notification();

            RequestLocationDataVM rldvm = new RequestLocationDataVM();

            try
            {
                #region Save Notification Type in DeviceAssociateSite
                if (model.NotificationType != null && model.MacAddressList != null && model.MacAddressList.Length > 0)
                {
                    using (ApplicationDbContext db = new ApplicationDbContext())
                    {
                        foreach (var mac in model.MacAddressList)
                        {
                            if (db.Device.Any(m => m.MacAddress == mac))
                            {
                                var ObjMacNotify = db.DeviceAssociateSite.First(m => m.Device.MacAddress == mac && m.SiteId == model.SiteId);
                                if (model.NotificationType == NotificationType.Entry)
                                {
                                    ObjMacNotify.IsTrackByAdmin = true;
                                }
                                else if (model.NotificationType == NotificationType.Approach)
                                {
                                    ObjMacNotify.IsEntryNotify = true;
                                }
                                else if (model.NotificationType == NotificationType.All)
                                {
                                    ObjMacNotify.IsTrackByAdmin = true; ObjMacNotify.IsEntryNotify = true;
                                }
                                db.Entry(ObjMacNotify).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                        }
                    }
                }
                #endregion

                #region Register MAC Address to RTLS
                if (model.MacAddressList.Length > 0)
                {
                    string[] RegisteredMacAdress; List <string> lstDeviceToRegister = new List <string>();
                    using (MacAddressRepository macRepo = new MacAddressRepository())
                    {
                        RegisteredMacAdress = macRepo.GetMacByStatus(DeviceStatus.Registered);
                    }
                    if (RegisteredMacAdress != null & RegisteredMacAdress.Length > 0)
                    {
                        foreach (var mac in model.MacAddressList)
                        {
                            if (!RegisteredMacAdress.Contains(mac))
                            {
                                lstDeviceToRegister.Add(mac);
                            }
                        }
                    }
                    else
                    {
                        lstDeviceToRegister.AddRange(model.MacAddressList);
                    }

                    rldvm.SiteName     = "";
                    rldvm.MacAddresses = lstDeviceToRegister.ToArray();
                    rldvm.SiteId       = model.SiteId;
                    try
                    {
                        await AddDevices(rldvm);
                    }
                    catch
                    {
                        //TODO Possible duplicate mac address error.
                    }
                }
                #endregion

                objNotifications.result.returncode = 0;
                objNotifications.result.errmsg     = "Success";
            }
            catch (Exception e)
            {
                objNotifications.result.returncode = -1;
                objNotifications.result.errmsg     = e.Message;
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 17
0
        public async Task <HttpResponseMessage> StopNotification(NotificationRequest model)
        {
            Notification          objNotifications        = new Notification();
            bool                  isAreaNotificationExist = false;
            RequestLocationDataVM rldvm = new RequestLocationDataVM();

            try
            {
                #region Remove ResetTime in RtlsConfiguration

                //Remove notification Reset Time
                //TODO Check with Jon- if we need to remove the site level configuration.
                RtlsConfiguration objrtls = objRtlsConfigurationRepository.GetAsPerSiteId(model.SiteId);
                if (objrtls != null)
                {
                    if (model.NotificationType == NotificationType.Entry)
                    {
                        objrtls.AreaNotification = 0;
                    }
                    else if (model.NotificationType == NotificationType.Approach)
                    {
                        objrtls.ApproachNotification = 0;
                    }
                    else if (model.NotificationType == NotificationType.All)
                    {
                        objrtls.ApproachNotification = 0;
                        objrtls.AreaNotification     = 0;
                    }
                    objRtlsConfigurationRepository.SaveAndUpdateAsPerSite(objrtls);
                }

                #endregion


                #region Remove Notification Type in DeviceAssociateSite
                if (model.NotificationType != null && model.MacAddressList != null && model.MacAddressList.Length > 0)
                {
                    using (ApplicationDbContext db = new ApplicationDbContext())
                    {
                        foreach (var mac in model.MacAddressList)
                        {
                            if (db.Device.Any(m => m.MacAddress == mac))
                            {
                                var ObjMacNotify = db.DeviceAssociateSite.First(m => m.Device.MacAddress == mac && m.SiteId == model.SiteId);
                                if (model.NotificationType == NotificationType.Entry)
                                {
                                    ObjMacNotify.IsTrackByAdmin = false;
                                }
                                else if (model.NotificationType == NotificationType.Approach)
                                {
                                    ObjMacNotify.IsEntryNotify = false;
                                }
                                else if (model.NotificationType == NotificationType.All)
                                {
                                    ObjMacNotify.IsTrackByAdmin = false; ObjMacNotify.IsEntryNotify = false;
                                }
                                db.Entry(ObjMacNotify).State = EntityState.Modified;
                                db.SaveChanges();

                                #region check if this Mac adress have any of notification enabled.
                                if (ObjMacNotify.IsTrackByAdmin || ObjMacNotify.IsEntryNotify)
                                {
                                    List <string> list = new List <string>(model.MacAddressList);
                                    list.Remove(mac);
                                    model.MacAddressList = list.ToArray();
                                }
                                if (ObjMacNotify.IsTrackByAdmin)
                                {
                                    isAreaNotificationExist = true;
                                }
                                #endregion
                            }
                        }
                    }
                }
                #endregion

                #region Remove Area in RtlsArea
                //TODO Check with Jon If need to remove site level configuration
                using (RtlsAreaApiRepository rtlsRepo = new RtlsAreaApiRepository())
                {
                    if ((model.NotificationType == NotificationType.Entry || model.NotificationType == NotificationType.All) && !isAreaNotificationExist)
                    {
                        rtlsRepo.RemoveAreaAsPerSite(model.SiteId);
                    }
                }

                #endregion

                #region De-Register MAC Address to RTLS
                if (model.MacAddressList.Length > 0)
                {
                    rldvm.SiteId = model.SiteId;
                    string[] RegisteredMacAdress; List <string> lstDeviceToRegister = new List <string>();
                    using (MacAddressRepository macRepo = new MacAddressRepository())
                    {
                        RegisteredMacAdress = macRepo.GetMacByStatus(DeviceStatus.DeRegistered);
                    }
                    if (RegisteredMacAdress != null & RegisteredMacAdress.Length > 0)
                    {
                        foreach (var mac in model.MacAddressList)
                        {
                            if (!RegisteredMacAdress.Contains(mac))
                            {
                                lstDeviceToRegister.Add(mac);
                            }
                        }
                    }
                    else
                    {
                        lstDeviceToRegister.AddRange(model.MacAddressList);
                    }

                    rldvm.SiteName     = "";
                    rldvm.MacAddresses = lstDeviceToRegister.ToArray();
                    try
                    {
                        await DeRegisterDevices(rldvm);
                    }
                    catch
                    {
                        //TODO Possible duplicate mac address error.
                    }
                }
                #endregion

                objNotifications.result.returncode = 0;
                objNotifications.result.errmsg     = "Success";
            }
            catch (Exception e)
            {
                objNotifications.result.returncode = -1;
                objNotifications.result.errmsg     = e.Message;
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objNotifications), Encoding.UTF8, "application/json")
            });
        }