Ejemplo n.º 1
0
        public HttpResponseMessage GetStatusOfUserForSite(LoginWIthNewMacAddressModel model)
        {
            AutoLoginStatus returnStatus = new AutoLoginStatus();

            try
            {
                //Need to check the MacAddress exist for the particular Site with Autologin true
                if (MacAddressRepository.IsMacAddressExistInParticularSite(model.MacAddress, model.SiteId))
                {
                    log.Info("inside Is Any MacAddressExist For Particular Site");
                    var User = UserRepository.GetUserPerDeviceMacAddress(model.MacAddress, model.SiteId);
                    if (User.AutoLogin == true)
                    {
                        log.Info("Check the AutoLogin of Site or User");
                        //objReturn.returncode = Convert.ToInt32(ReturnCode.Success);
                        returnStatus.UserName = User.UserName;
                        returnStatus.Password = User.PasswordHash;
                        returnStatus.StatusReturn.ReturnCode = Convert.ToInt32(ReturnCode.Success);
                    }
                }
                else
                {
                    returnStatus.StatusReturn.ReturnCode = Convert.ToInt32(ReturnCode.Warning);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                returnStatus.StatusReturn.ReturnCode = Convert.ToInt32(ReturnCode.Failure);
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(returnStatus), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 2
0
        public HttpResponseMessage UpdateMacAddress(MemberDevicesModel objUserMac)
        {
            StatusReturn objReturn = null;

            try
            {
                if (ApiUserSessionRepository.IsAuthorize(objUserMac.SessionId))
                {
                    if (objUserMac.OperationType == OperationType.Add)
                    {
                        var retResult = MacAddressRepository.RegisterListOfMacAdressToDb(objUserMac);
                        if (retResult == RepositoryResult.Success)
                        {
                            using (CommunicateRTLS objCommunicateRtls = new CommunicateRTLS())
                            {
                                string       strResult        = objCommunicateRtls.RegisterInRealTimeLocationService(objUserMac.MacAddressList.Select(m => m.MacAddress).ToArray()).Result;
                                Notification objServiceReturn = JsonConvert.DeserializeObject <Notification>(strResult);
                                if (objServiceReturn.result.returncode == Convert.ToInt32(RTLSResult.Success))
                                {
                                    objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.Success), ReturnCode.Success.ToString(), " ");
                                }
                            }
                        }
                    }
                    else if (objUserMac.OperationType == OperationType.Delete)
                    {
                        var retResult = MacAddressRepository.RemoveListOfMacAddressFromDb(objUserMac);
                        if (retResult == RepositoryResult.Success)
                        {
                            using (CommunicateRTLS objCommunicateRtls = new CommunicateRTLS())
                            {
                                string       strResult        = objCommunicateRtls.DeregisterInRealTimeLocationServices(objUserMac.MacAddressList.Select(m => m.MacAddress).ToArray()).Result;
                                Notification objServiceReturn = JsonConvert.DeserializeObject <Notification>(strResult);
                                if (objServiceReturn.result.returncode == Convert.ToInt32(RTLSResult.Success))
                                {
                                    objReturn = new StatusReturn(Convert.ToInt32(ErrorCodeWarning.SessionIdRequired), ReturnCode.Success.ToString(), " ");
                                }
                            }
                        }
                        else
                        {
                            //Missing or Invalid Operation Type
                        }
                    }
                    else
                    {
                        objReturn = new StatusReturn(Convert.ToInt32(ErrorCodeWarning.NonAuthorize), ReturnCode.Warning.ToString(), "Invalid SessionId");
                    }
                }
            }
            catch (Exception ex)
            {
                objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.Failure), ReturnCode.Failure.ToString(), "some problem occured");
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objReturn), Encoding.UTF8, "application/json")
            });
        }
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 HttpResponseMessage CreateUserWifi(UserMacAddressDetails objUserMac)
        {
            StatusReturn objReturn = null;

            if (!ModelState.IsValid)
            {
                var response = Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                return(response);
            }
            try
            {
                RepositoryResult repResult = UserRepository.CreateWifiUser(objUserMac.objUser);
                if (repResult == RepositoryResult.Success)
                {
                    repResult = UserRepository.CreateUserRole(objUserMac.objUser);
                    if (repResult == RepositoryResult.Success)
                    {
                        objUserMac.objMacAddress.UserId = objUserMac.objUser.Id;
                        repResult = MacAddressRepository.CreateNewMacDevice(objUserMac.objMacAddress);
                        if (repResult == RepositoryResult.Success)
                        {
                            objUserMac.objAddress.UserId = objUserMac.objUser.Id;
                            repResult = UserAddressRepository.CreateUserAddress(objUserMac.objAddress);
                            if (repResult == RepositoryResult.Success)
                            {
                                //objRegisterDB.CreateNewUser(objUserMac.objUser.UserName, objUserMac.objUser.PasswordHash, objUserMac.objUser.Email, objUserMac.objUser.FirstName, objUserMac.objUser.LastName);
                                if (UserRepository.IsMemeber(objUserMac.objUser.UserName) && MacAddressRepository.IsMacAddressExistInParticularSite(objUserMac.objMacAddress.MacAddressValue, (int)objUserMac.objUser.SiteId))
                                {
                                    using (CommunicateRTLS objCommunicateRtls = new CommunicateRTLS())
                                    {
                                        string       retResult        = objCommunicateRtls.RegisterInRealTimeLocationService(new[] { objUserMac.objMacAddress.MacAddressValue }).Result;
                                        Notification objServiceReturn = JsonConvert.DeserializeObject <Notification>(retResult);
                                        if (objServiceReturn.result.returncode == Convert.ToInt32(RTLSResult.Success))
                                        {
                                            MacAddressRepository.RegisterMacAddressToRtls(objUserMac.objMacAddress.MacAddressValue);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.Success), ReturnCode.Success.ToString(), Common.Common.Reg_Success);
                    //dbContextTransaction.Commit();
                }
            }
            catch (Exception ex)
            {
                //dbContextTransaction.Rollback();
                objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.Failure), ReturnCode.Success.ToString(), Common.Common.Reg_Success);
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objReturn), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 5
0
        public HttpResponseMessage Login(LoginWIthNewMacAddressModel model)
        {
            StatusReturn objReturn = null;

            try
            {
                if (!ModelState.IsValid)
                {
                    var response = Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                    return(response);
                }
                if (!UserRepository.IsNewUserAsPerSite(model.UserName, model.SiteId))
                {
                    var objWifiUsers = UserRepository.GetUniqueUserPerSite(model.UserName, model.SiteId);
                    if (!MacAddressRepository.IsMacAddressExistInParticularSite(model.MacAddress, model.SiteId))
                    {
                        //log.Info("Check that the particular MacAddress exist or Not for particualr User with Different Site";
                        MacAddress objMac = new MacAddress();
                        objMac.MacAddressValue = model.MacAddress;
                        objMac.UserId          = objWifiUsers.Id;
                        objMac.BrowserName     = model.BrowserName;
                        objMac.UserAgentName   = model.UserAgentName;
                        objMac.OperatingSystem = model.OperatingSystem;
                        objMac.IsMobile        = model.IsMobile;
                        MacAddressRepository.CreateNewMacDevice(objMac);

                        //Save all the Users data in MySql DataBase
                        if (UserRepository.IsMemeber(model.UserName) && MacAddressRepository.IsMacAddressExistInParticularSite(model.UserName, (int)model.SiteId))
                        {
                            using (CommunicateRTLS objCommunicateRtls = new CommunicateRTLS())
                            {
                                string       retResult        = objCommunicateRtls.RegisterInRealTimeLocationService(new[] { model.MacAddress }).Result;
                                Notification objServiceReturn = JsonConvert.DeserializeObject <Notification>(retResult);
                                if (objServiceReturn.result.returncode == Convert.ToInt32(RTLSResult.Success))
                                {
                                    MacAddressRepository.RegisterMacAddressToRtls(model.MacAddress);
                                }
                            }
                        }
                    }
                }
                objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.Success), ReturnCode.Success.ToString(), Common.Common.Reg_Success);
            }
            catch (Exception ex)
            {
                objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.Failure), ReturnCode.Success.ToString(), Common.Common.Reg_Success);
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objReturn), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 6
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.º 7
0
        public async Task <HttpResponseMessage> AddDevice(RequestOmniModel objRequestOmniModel)
        {
            //objRequestOmniModel.MacAddress= "7z:c5:37:c0:83:y3";
            //create the RequestModel for secom api
            string result = null;

            try
            {
                using (RtlsConfigurationRepository objRtlsConfigurationRepository = new RtlsConfigurationRepository())
                {
                    //Get the EngageEngine Base Url as per SiteId
                    Site objSiteConfiguration = objRtlsConfigurationRepository.GetAsPerSite(objRequestOmniModel.SiteId);
                    if (objSiteConfiguration.RtlsConfiguration.RtlsEngineType == RtlsEngine.OmniEngine)
                    {
                        OmniEngineBusiness objOmniEngineBusiness = new OmniEngineBusiness();
                        await objOmniEngineBusiness.regMacToOmniEngine(objRequestOmniModel);

                        using (MacAddressRepository objMacAddressRepository = new MacAddressRepository())
                        {
                            objMacAddressRepository.UpdateLocationServiceTypeforMac(objRequestOmniModel, objSiteConfiguration.RtlsConfiguration.RtlsEngineType);
                        }
                        //string OmniBaseAddressUri = objSiteConfiguration.RtlsConfiguration.OmniBaseAddressUri;
                    }
                    if (objSiteConfiguration.RtlsConfiguration.RtlsEngineType == RtlsEngine.EngageEngine)
                    {
                        EngageEngineBusiness objEngageEngineBusiness = new EngageEngineBusiness();
                        if (await objEngageEngineBusiness.regMacToEngageEngine(objRequestOmniModel))
                        {
                            using (MacAddressRepository objMacAddressRepository = new MacAddressRepository())
                            {
                                objMacAddressRepository.UpdateLocationServiceTypeforMac(objRequestOmniModel, objSiteConfiguration.RtlsConfiguration.RtlsEngineType);
                            }
                        }
                        //string EngageBaseAddressUri = objSiteConfiguration.RtlsConfiguration.EngageBaseAddressUri;
                    }
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
                log.Error(ex.Message);
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(result), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 8
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.º 9
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.º 10
0
        public HttpResponseMessage GetMacAddress(MemberViewModel model)
        {
            ReturnMacDevices objReturnMac = new ReturnMacDevices();
            StatusReturn     objReturn    = new StatusReturn();

            try
            {
                if (ApiUserSessionRepository.IsAuthorize(model.SessionId))
                {
                    if (UserRepository.IsNewMemberAsPerSite(model.UserId, model.SiteId))
                    {
                        string[] Macs = MacAddressRepository.GetListMacAddress(model.UserId, model.SiteId);
                        foreach (var item in Macs)
                        {
                            MacAddesses objMacAddress = new MacAddesses();
                            objMacAddress.MacAddress = item;
                            objReturnMac.MacAddressList.Add(objMacAddress);
                        }
                        objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.GetMacAddressSuccess), ReturnCode.Success.ToString(), "Successfully return the MacAddresses");
                    }
                    else
                    {
                        objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.Warning), ReturnCode.Warning.ToString(), "UserId or SiteId Not Exist");
                    }
                }
                else
                {
                    objReturn = new StatusReturn(Convert.ToInt32(ErrorCodeWarning.NonAuthorize), ErrorCodeWarning.NonAuthorize.ToString(), "Invalid SesssionId" + " " + model.SessionId);
                }
            }
            catch (Exception ex)
            {
                objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.Failure), ReturnCode.Failure.ToString(), "Error Occured");
            }
            objReturnMac.objReturn = objReturn;
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objReturnMac), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 11
0
        public HttpResponseMessage DeleteWiFiUser(MemberViewModel model)
        {
            StatusReturn objReturn = null;

            try
            {
                if (ApiUserSessionRepository.IsAuthorize(model.SessionId))
                {
                    if (UserRepository.IsMemberRegisterInRTLS(model.UserId, model.SiteId))
                    {
                        using (CommunicateRTLS objCommunicateRtls = new CommunicateRTLS())
                        {
                            var          lstMacAddress    = MacAddressRepository.GetListMacAddress(model.UserId, model.SiteId);
                            string       retResult        = objCommunicateRtls.DeregisterInRealTimeLocationServices(lstMacAddress).Result;
                            Notification objServiceReturn = JsonConvert.DeserializeObject <Notification>(retResult);
                            if (objServiceReturn.result.returncode == Convert.ToInt32(RTLSResult.Success))
                            {
                                UserRepository.RemoveMemberAsUserUniqueId(model.UserId, model.SiteId);
                                objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.DeleteUserSuccess), ReturnCode.DeleteUserSuccess.ToString(), "User Deleted");
                            }
                        }
                    }
                }
                else
                {
                    objReturn = new StatusReturn(Convert.ToInt32(ErrorCodeWarning.NonAuthorize), ReturnCode.Warning.ToString(), "Invalid SessionId");
                }
            }
            catch (Exception ex)
            {
                objReturn = new StatusReturn(Convert.ToInt32(ReturnCode.Failure), ReturnCode.Failure.ToString(), "Error Occured");
            }
            return(new HttpResponseMessage()
            {
                Content = new StringContent(JsonConvert.SerializeObject(objReturn), Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 12
0
 public MemberApiController(UserRepository userRepo, MacAddressRepository macAddressRepo, UserAddressRepository userAddressRepo, ApiAccessUserSessionRepository apiUserSessionRepo)
 {
     UserRepository           = userRepo;
     MacAddressRepository     = macAddressRepo;
     ApiUserSessionRepository = apiUserSessionRepo;
 }
Ejemplo n.º 13
0
 public AccountApiController(UserRepository userRepo, MacAddressRepository macAddressRepo, UserAddressRepository userAddressRepo)
 {
     UserRepository       = userRepo;
     MacAddressRepository = macAddressRepo;
 }
Ejemplo n.º 14
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.º 15
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")
            });
        }
Ejemplo n.º 16
0
 public OmniEngineBusiness()
 {
     objOmniDeviceMappingRepository = new OmniDeviceMappingRepository();
     objMacAddressRepository        = new MacAddressRepository();
 }
Ejemplo n.º 17
0
 public OmniDeviceMappingRepository()
 {
     db = new ApplicationDbContext();
     _MacAddressRepository = new MacAddressRepository();
 }
Ejemplo n.º 18
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.º 19
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.º 20
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")
            });
        }