Пример #1
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;
            }
        }
Пример #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)
                {
                    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")
            });
        }
Пример #3
0
        public string CheckDeviceRegisted(MonitorDevices model, int siteid)
        {
            string adminMessage = "";

            try
            {
                foreach (var rec in model.records)
                {
                    //If MacAddress already exist with None status then
                    if (db.Device.Any(m => m.MacAddress == rec.device_id))
                    {
                        var objMac = db.Device.FirstOrDefault(m => m.MacAddress == rec.device_id);
                        if (db.DeviceAssociateSite.Any(m => m.DeviceId == objMac.DeviceId))
                        {
                            var objDevice = db.DeviceAssociateSite.FirstOrDefault(m => m.DeviceId == objMac.DeviceId);
                            if (objDevice.status != DeviceStatus.Registered)
                            {
                                objDevice.DeviceRegisteredInEngineType = DeviceRegisteredInEngine.EngageEngine;
                                objDevice.status          = DeviceStatus.Registered;
                                db.Entry(objDevice).State = System.Data.Entity.EntityState.Modified;
                                db.SaveChanges();
                                adminMessage += "[ " + rec.device_id + " ] Change Device Status to Registered." +
                                                Environment.NewLine;
                            }
                        }
                        else
                        {
                            DeviceAssociateSite objDeviceAssociate = new DeviceAssociateSite();
                            objDeviceAssociate.SiteId          = siteid;
                            objDeviceAssociate.DeviceId        = objMac.DeviceId;
                            objDeviceAssociate.CreatedDateTime = DateTime.Now;
                            objDeviceAssociate.DeviceRegisteredInEngineType = DeviceRegisteredInEngine.EngageEngine;
                            //objDeviceAssociate.IsDeviceRegisterInRtls = true;
                            db.DeviceAssociateSite.Add(objDeviceAssociate);
                            db.SaveChanges();
                            adminMessage += "[ " + rec.device_id + " ]  Added to Associate Site Mapping." +
                                            Environment.NewLine;
                        }
                    }
                    else
                    {
                        Device objMac = new Device();
                        objMac.MacAddress = rec.device_id;
                        db.Device.Add(objMac);
                        db.SaveChanges();
                        DeviceAssociateSite objDeviceAssociate = new DeviceAssociateSite();
                        objDeviceAssociate.SiteId          = siteid;
                        objDeviceAssociate.DeviceId        = objMac.DeviceId;
                        objDeviceAssociate.CreatedDateTime = DateTime.Now;
                        //change
                        //objDeviceAssociate.IsDeviceRegisterInRtls = true;
                        objDeviceAssociate.DeviceRegisteredInEngineType = DeviceRegisteredInEngine.EngageEngine;
                        objDeviceAssociate.status = DeviceStatus.Registered;
                        db.DeviceAssociateSite.Add(objDeviceAssociate);
                        db.SaveChanges();
                        adminMessage += "[ " + rec.device_id + " ]  Added to Device & Associate Site Mapping." +
                                        Environment.NewLine;
                    }
                }
                if (string.IsNullOrEmpty(adminMessage))
                {
                    adminMessage += "All Device Validated for Registration . Status OK ." +
                                    Environment.NewLine;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(adminMessage);
        }
Пример #4
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")
            });
        }
Пример #5
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")
            });
        }