public ApiResponse GetNotifications(long lastNotificationID)
        {
            ApiResponse oApiResponse = new ApiResponse();
            if (User.Identity.Name == "")
            {
                ResultInfo.Result result = ResultInfo.GetResultByID(1);
                oApiResponse = ApiResponseAdapter.fromResult(result);
                return oApiResponse;
            }

            try
            {
                oApiResponse.Status = "Ok";
                int notisCount = UnitOfWork_Repositories.repoUserNotification.GetUnseenNotifications( User.Identity.GetUserId(), lastNotificationID).Count;
                oApiResponse.Message = notisCount.ToString();
            }
            catch (Exception ex)
            {
                ResultInfo.Result result = ResultInfo.GetResultByID(1);
                oApiResponse = ApiResponseAdapter.fromResult(result);
            }
            return oApiResponse;
        }
Ejemplo n.º 2
0
        private ApiResponse CoreSubmitEndPointInput(Models.SubmissionEndPointIO oEndPointInput)
        {
            ApiResponse oApiResponse = new ApiResponse();
            //Validate KeyPass
            try
            {
                if (string.IsNullOrEmpty(oEndPointInput.KeyPass))
                {
                    ResultInfo.Result result = ResultInfo.GetResultByID(1);
                    oApiResponse = ApiResponseAdapter.fromResult(result);
                    return oApiResponse;
                }

                Guid endPointKeyPass;
                if (Guid.TryParse(oEndPointInput.KeyPass, out endPointKeyPass))
                {
                    //endPoint keyPass Validation
                    DynThings.Data.Models.Endpoint oEndpoint = UnitOfWork_Repositories.repoEndpoints.FindByKeyPass(endPointKeyPass);

                    if (oEndpoint != null)
                    {
                        //Try Parse ExecutionTimeStamp to DateTime
                        DateTime execTime;
                        if (oEndPointInput.ExectionTimeStamp == "")
                        {
                            oEndPointInput.ExectionTimeStamp = DateTime.UtcNow.AddHours(int.Parse(oEndpoint.Device.UTC_Diff.ToString())).ToString();
                        }
                        if (DateTime.TryParse(oEndPointInput.ExectionTimeStamp, out execTime))
                        {
                        }
                        else
                        {//DateTime Parse Failed
                            ResultInfo.Result result = ResultInfo.GetResultByID(1);
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return oApiResponse;
                        }

                        //Submit Data to Database
                        ResultInfo.Result repoResult = UnitOfWork_Repositories.repoEndpointIOs.Add(oEndpoint.ID, oEndPointInput.Value.ToString(), EndpointIOsRepository.EndPointIOType.Input, execTime);

                        //Validate Result
                        if (repoResult.ResultType == ResultInfo.ResultType.Ok)
                        {//Submited
                            ResultInfo.Result result = ResultInfo.GenerateOKResult();
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            SignalRServices.ThingEnd_Input(oEndpoint.ThingID , oEndpoint.EndPointType.ID);
                            return oApiResponse;
                        }
                        else
                        {//Submition Failed
                            ResultInfo.Result result = ResultInfo.GetResultByID(1);
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return oApiResponse;
                        }
                    }
                }
                else
                {// KeyPass Parse Failed
                    ResultInfo.Result result = ResultInfo.GetResultByID(1);
                    oApiResponse = ApiResponseAdapter.fromResult(result);
                    return oApiResponse;
                }

            }
            catch (Exception ex)
            {
                ResultInfo.Result result = ResultInfo.GetResultByID(1);
                oApiResponse = ApiResponseAdapter.fromResult(result);
            }
            return oApiResponse;
        }
Ejemplo n.º 3
0
        public ApiResponse SubmitDeviceLog(Models.SubmissionDeviceIO deviceInput)
        {
            ApiResponse oApiResponse = new ApiResponse();
            //Validate KeyPass
            try
            {
                if (string.IsNullOrEmpty(deviceInput.KeyPass))
                {
                    ResultInfo.Result result = ResultInfo.GetResultByID(1);
                    oApiResponse = ApiResponseAdapter.fromResult(result);

                    return oApiResponse;
                }

                //Parse KeyPass
                Guid deviceGuid;
                if (Guid.TryParse(deviceInput.KeyPass, out deviceGuid))
                {
                    //Device keyPass Validation
                    DynThings.Data.Models.Device device = UnitOfWork_Repositories.repoDevices.FindByKeyPass(deviceGuid);
                    if (device != null)
                    {
                        //Try Parse ExecutionTimeStamp to DateTime
                        DateTime execTime;
                        if (DateTime.TryParse(deviceInput.ExectionTimeStamp, out execTime))
                        { }
                        else
                        {//DateTime Parse Failed
                            ResultInfo.Result result = ResultInfo.GetResultByID(1);
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return oApiResponse;
                        }

                        //Submit Data to Database
                        ResultInfo.Result repoResult = UnitOfWork_Repositories.repoDeviceIOs.Add(device.ID, deviceInput.Value.ToString(), DeviceIOsRepository.deviceIOType.Log, execTime);

                        //Validate Result
                        if (repoResult.ResultType == ResultInfo.ResultType.Ok)
                        {//Submited
                            ResultInfo.Result result = ResultInfo.GenerateOKResult();
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return oApiResponse;
                        }
                        else
                        {//Submition Failed
                            ResultInfo.Result result = ResultInfo.GetResultByID(1);
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return oApiResponse;
                        }
                    }
                }
                else
                {// KeyPass Parse Failed
                    ResultInfo.Result result = ResultInfo.GetResultByID(1);
                    oApiResponse = ApiResponseAdapter.fromResult(result);
                    return oApiResponse;
                }

            }
            catch (Exception)
            {
                ResultInfo.Result result = ResultInfo.GetResultByID(1);
                oApiResponse = ApiResponseAdapter.fromResult(result);
            }
            return oApiResponse;
        }