private ApiResponse CoreSubmitEndPointInput(Models.SubmissionEndPointIO oEndPointInput)
        {
            ApiResponse oApiResponse = new ApiResponse();

            try
            {
                //Validate KeyPass
                if (string.IsNullOrEmpty(oEndPointInput.KeyPass))
                {
                    ResultInfo.Result result = ResultInfo.GenerateErrorResult("Keypass is missing");
                    oApiResponse = ApiResponseAdapter.fromResult(result);
                    return(oApiResponse);
                }

                Guid endPointKeyPass;
                if (Guid.TryParse(oEndPointInput.KeyPass, out endPointKeyPass))
                {
                    //endPoint keyPass Validation
                    DynThings.Data.Models.Endpoint oEndpoint = uof_repos.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.GenerateErrorResult("DateTime is not in correct format");
                            oApiResponse = ApiResponseAdapter.fromResult(result);
                            return(oApiResponse);
                        }

                        //Submit Data to Database
                        ResultInfo.Result repoResult = uof_repos.repoEndpointIOs.SubmitInput(endPointKeyPass, oEndPointInput.Value.ToString(), execTime);

                        oApiResponse = ApiResponseAdapter.fromResult(repoResult);
                    }
                }
                else
                {// KeyPass Parse Failed
                    ResultInfo.Result result = ResultInfo.GenerateErrorResult("Keypass is not valid");
                    oApiResponse = ApiResponseAdapter.fromResult(result);
                    return(oApiResponse);
                }
            }
            catch (Exception ex)
            {
                ResultInfo.Result result = ResultInfo.GetResultByID(1);
                oApiResponse = ApiResponseAdapter.fromResult(result);
            }
            return(oApiResponse);
        }
        private ApiResponse CoreSetEndPointPendingCommandAsExecuted(SubmissionEndPointCommandExecuted submission)
        {
            ApiResponse oApiResponse = ApiResponseAdapter.fromResult(ResultInfo.GenerateErrorResult());

            try
            {
                return(ApiResponseAdapter.fromResult(uof_repos.repoEndpointIOs.SetCommandAsExecuted(submission.EndPointCommandIOID, submission.EndPointKeyPass, submission.ExectionTimeStamp)));
            }
            catch
            {
            }
            return(oApiResponse);
        }
        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.StatusTitle = "Ok";
                int notisCount = uof_repos.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);
        }
        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 = uof_repos.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 = uof_repos.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);
        }
        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);
                            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);
        }