Пример #1
0
        //[6][1] 입력
        public async Task <CommonValue> AddAsync(CommonValue model)
        {
            #region CommonValue 기능 추가
            // 현재테이블의 Ref의 Max값 가져오기
            int maxRef = 1;
            int?max    = _context.CommonValues.Max(m => m.Ref);
            if (max.HasValue)
            {
                maxRef = (int)max + 1;
            }

            model.Ref      = maxRef;
            model.Step     = 0;
            model.RefOrder = 0;
            #endregion

            try
            {
                _context.CommonValues.Add(model);
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                _logger.LogError($"ERROR({nameof(AddAsync)}): {e.Message}");
            }

            return(model);
        }
Пример #2
0
        //[6][4] 수정
        public async Task <bool> EditAsync(CommonValue model)
        {
            try
            {
                _context.CommonValues.Attach(model);
                _context.Entry(model).State = EntityState.Modified;
                return(await _context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (Exception e)
            {
                _logger.LogError($"ERROR({nameof(EditAsync)}): {e.Message}");
            }

            return(false);
        }
Пример #3
0
        public async Task <ArticleSet <CommonValue, int> > GetArticles <TParentIdentifier>(int pageIndex, int pageSize, string searchField, string searchQuery, string sortOrder, TParentIdentifier parentIdentifier)
        {
            // Default Values
            if (!_context.CommonValues.Any())
            {
                var model = new CommonValue()
                {
                    Name = " ", Category = "Projects", SubCategory = "Vetting Steps", VariableText = "# of Signers", VariableValue = "2"
                };
                await AddAsync(model);

                _context.SaveChanges();
            }

            //var items = from m in _context.CommonValues select m; // 쿼리 구문(Query Syntax)
            var items = _context.CommonValues.Select(m => m); // 메서드 구문(Method Syntax)

            // ParentBy
            if (parentIdentifier is int parentId && parentId != 0)
            {
                items = items.Where(m => m.ParentId == parentId);
            }