public string Save(StudentResult studentResult)
        {
            StudentResult result =
                GetAllResult.ToList()
                .Find(st => st.StudentId == studentResult.StudentId && st.CourseId == studentResult.CourseId);

            if (result == null)
            {
                if (studentGateway.Insert(studentResult) > 0)
                {
                    return("Saved sucessfull!");
                }
                return("Failed to save");
            }
            if (result.Status)
            {
                return("This course result already saved");
            }
            if (studentGateway.UpdateStudentResult(studentResult) > 0)
            {
                return("Saved sucessfull!");
            }

            return("This course result already saved");
        }
示例#2
0
            public async Task GetAll_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
            {
                var args = new GetAllArgs();
                await args.ReadAsync(iprot, cancellationToken);

                await iprot.ReadMessageEndAsync(cancellationToken);

                var result = new GetAllResult();

                try
                {
                    result.Success = await _iAsync.GetAllAsync(cancellationToken);

                    await oprot.WriteMessageBeginAsync(new TMessage("GetAll", TMessageType.Reply, seqid), cancellationToken);

                    await result.WriteAsync(oprot, cancellationToken);
                }
                catch (TTransportException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Error occurred in processor:");
                    Console.Error.WriteLine(ex.ToString());
                    var x = new TApplicationException(TApplicationException.ExceptionType.InternalError, " Internal error.");
                    await oprot.WriteMessageBeginAsync(new TMessage("GetAll", TMessageType.Exception, seqid), cancellationToken);

                    await x.WriteAsync(oprot, cancellationToken);
                }
                await oprot.WriteMessageEndAsync(cancellationToken);

                await oprot.Transport.FlushAsync(cancellationToken);
            }
示例#3
0
            public async Task <List <User> > GetAllAsync(CancellationToken cancellationToken)
            {
                await OutputProtocol.WriteMessageBeginAsync(new TMessage("GetAll", TMessageType.Call, SeqId), cancellationToken);

                var args = new GetAllArgs();

                await args.WriteAsync(OutputProtocol, cancellationToken);

                await OutputProtocol.WriteMessageEndAsync(cancellationToken);

                await OutputProtocol.Transport.FlushAsync(cancellationToken);

                var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);

                if (msg.Type == TMessageType.Exception)
                {
                    var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);

                    await InputProtocol.ReadMessageEndAsync(cancellationToken);

                    throw x;
                }

                var result = new GetAllResult();
                await result.ReadAsync(InputProtocol, cancellationToken);

                await InputProtocol.ReadMessageEndAsync(cancellationToken);

                if (result.__isset.success)
                {
                    return(result.Success);
                }
                throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "GetAll failed: unknown result");
            }
示例#4
0
        public static List <User> GetUsers(string condition = "")
        {
            GetAllResult userListResult = ClarizenAPI.GetAll("User", typeof(User), new cZQLCondition(condition));

            List <User> users = (List <User>)userListResult.Data;

            users = users?.OrderBy(i => i.DisplayName).ToList();

            return(users);
        }
        protected Record[] GetLookUp(GetAllRecordType recordType)
        {
            GetAllRecord record = new GetAllRecord();

            record.recordTypeSpecified = true;
            record.recordType          = recordType;
            GetAllResult gr = new GetAllResult();

            gr = Service(true).getAll(record);
            return(gr.recordList);
        }
                public GetAllResult DeepCopy()
                {
                    var tmp12 = new GetAllResult();

                    if ((Success != null) && __isset.success)
                    {
                        tmp12.Success = this.Success.DeepCopy();
                    }
                    tmp12.__isset.success = this.__isset.success;
                    return(tmp12);
                }
        private bool IsResulExits(StudentResult studentResult)
        {
            StudentResult result =
                GetAllResult.ToList()
                .Find(st => st.StudentId == studentResult.StudentId && st.CourseId == studentResult.CourseId);

            if (result != null)
            {
                return(true);
            }
            return(false);
        }
    public static void FillCache()
    {
        GetAllRecord getAllStates = new GetAllRecord();

        getAllStates.recordType          = GetAllRecordType.state;
        getAllStates.recordTypeSpecified = true;
        GetAllResult stateResult = _service.getAll(getAllStates);

        Record[] stateRecords = stateResult.recordList;
        if (stateResult.status.isSuccess)
        {
            foreach (State state in stateRecords)
            {
                Cache[state.fullName.ToUpper()] = state.shortname;
            }
        }
        // and some code to do the rest of the web service calls until you have all results.
    }
        public List <T> LoadAll(string customCondition = "", bool readFromFile = false, bool useCache = false, int cacheDuration = 60)
        {
            string entityName = typeof(T).Name;
            var    items      = new List <T>();
            var    file       = GetFilePath(entityName);

            if (readFromFile && string.IsNullOrEmpty(customCondition))
            {
                var fileInfo = new FileInfo(file);
                if (fileInfo.Exists)
                {
                    items = FileHelper.ReadFromJsonFile <List <T> >(file);
                    return(items);
                }
            }

            var cacheKey = $"LoadAllByType:{entityName}:{GetEnvironmentSuffix()}:{customCondition}";

            if (useCache && _cacheManager != null)
            {
                items = _cacheManager.Get <List <T> >(cacheKey);

                if (items != null)
                {
                    return(items);
                }
            }

            cZQLCondition condition = null;

            if (!string.IsNullOrEmpty(customCondition))
            {
                condition = new cZQLCondition(customCondition);
            }

            int currentRetry = 1;

            do
            {
                try
                {
                    GetAllResult result = _api.GetAll(entityName, typeof(T), condition);

                    if (result.Data == null || result.Errors.Count > 0)
                    {
                        items = null;

                        if (result != null && result.Errors.Any())
                        {
                            var msg         = "Error occured on Clarizen API call. Retry count: " + currentRetry;
                            var detailedMsg = "Error: " + string.Join(System.Environment.NewLine, result.Errors.Select(i => i.message));
                            throw new Exception(msg, new Exception(detailedMsg));
                        }
                    }
                    else
                    {
                        items = (List <T>)result.Data;
                        break;
                    }
                }
                catch (Exception ex)
                {
                    var msg = ExceptionHelper.GetExceptionErrorMessage(ex, "Exception in Clarizen Data LoadAllByType");
                    Debug.WriteLine(msg);

                    currentRetry++;

                    // Check if the exception thrown was a transient/timeout exception
                    // based on the logic in the error detection strategy.
                    // Determine whether to retry the operation, as well as how
                    // long to wait, based on the retry strategy.
                    if (currentRetry > API_RETRY_COUNT || !ex.Message.Contains("timed out"))
                    {
                        // If this isn't a transient error or we shouldn't retry,
                        // rethrow the exception.
                        items = new List <T>();
                    }
                }

                // Wait to retry the operation.
                // Consider calculating an exponential delay here and
                // using a strategy best suited for the operation and fault.
                Thread.Sleep(API_DELAY);
            } while (currentRetry <= API_RETRY_COUNT);

            if (useCache && _cacheManager != null)
            {
                _cacheManager.Set(cacheKey, items, cacheDuration);
            }

            if (readFromFile)
            {
                FileHelper.WriteToJsonFile(file, items);
            }

            return(items);
        }