Example #1
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")
            });
        }
Example #2
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")
            });
        }