/// <summary> /// /// </summary> /// <param name="model"></param> public void SaveAndUpdateAsPerSite(RtlsArea model) { if (CheckRtlsAreaExistOrNotAsPerSite((int)model.RtlsConfigurationId)) { int id = db.RtlsArea.FirstOrDefault(m => m.RtlsConfigurationId == model.RtlsConfigurationId).Id; model.Id = id; db.Entry(model).State = System.Data.Entity.EntityState.Modified; } else { db.RtlsArea.Add(model); } db.SaveChanges(); }
public HttpResponseMessage GetRtlsArea(RtlsArea model) { IEnumerable <RtlsArea> objRtlsArea = null; JsonSerializerSettings jsSettings = new JsonSerializerSettings(); try { objRtlsArea = objRtlsAreaApiRepository.GetListOfGeoFencedAreasPerSite(model.RtlsConfigurationId); jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; } catch (Exception ex) { log.Error(ex.InnerException.Message); } return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(objRtlsArea, Formatting.None, jsSettings), System.Text.Encoding.UTF8, "application/json") }); }
public HttpResponseMessage SaveAndUpdateRtlsTrigger(RtlsAreaViewModel lstRtlsAreas) { try { var RtlsConfig = objRtlsConfigurationRepository.GetAsPerSiteId(lstRtlsAreas.SiteId); RtlsConfig.ApproachNotification = lstRtlsAreas.ApproachNotification; RtlsConfig.AreaNotification = lstRtlsAreas.AreaNotification; objRtlsConfigurationRepository.SaveAndUpdateAsPerSite(RtlsConfig); List <RtlsArea> lstRtlsArea = new List <RtlsArea>(); if (lstRtlsAreas.GeoFencedAreas != null) { foreach (var item in lstRtlsAreas.GeoFencedAreas) { RtlsArea objRtlsArea = new RtlsArea(); objRtlsArea.GeoFencedAreas = item.GeoFencedAreas; objRtlsArea.RtlsConfigurationId = item.RtlsConfigurationId; objRtlsArea.Id = item.Id; lstRtlsArea.Add(objRtlsArea); } } if (lstRtlsArea.Any(m => m.Id == 0 && m.GeoFencedAreas != null)) { objRtlsAreaApiRepository.CreateAsPerSite(lstRtlsArea.Where(m => m.Id == 0).ToList()); } if (lstRtlsArea.Any(m => m.Id != 0)) { objRtlsAreaApiRepository.UpdateAsPerSite(lstRtlsArea.Where(m => m.Id != 0).ToList()); } } catch (Exception ex) { log.Error(ex.Message); } return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject("Success"), System.Text.Encoding.UTF8, "application/json") }); }
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") }); }