예제 #1
0
        public async Task <IActionResult> PostFilterRemoveAsync()
        {
            string strID = Request.Form["idField"];

            if (strID.Contains("-field"))
            {
                strID = strID.Replace("-field", "");
                bool ok = int.TryParse(strID, out int idField);
                if (!ok)
                {
                    return(Ok());
                }
                MtdFilterField mtdFilterField = new MtdFilterField {
                    Id = idField
                };
                try
                {
                    _context.MtdFilterField.Remove(mtdFilterField);
                    await _context.SaveChangesAsync();
                }
                catch (Exception ex) { throw ex.InnerException; }
            }

            if (strID.Contains("-date"))
            {
                strID = strID.Replace("-date", "");
                bool ok = int.TryParse(strID, out int idFilter);
                if (!ok)
                {
                    return(Ok());
                }
                MtdFilterDate filterDate = new MtdFilterDate {
                    Id = idFilter
                };
                try
                {
                    _context.MtdFilterDate.Remove(filterDate);
                    await _context.SaveChangesAsync();
                }
                catch (Exception ex) { throw ex.InnerException; }
            }

            if (strID.Contains("-script"))
            {
                strID = strID.Replace("-script", "");
                bool ok = int.TryParse(strID, out int idFilter);
                if (!ok)
                {
                    return(Ok());
                }
                MtdFilterScript mtdFilterScript = await _context.MtdFilterScript.FindAsync(idFilter);

                mtdFilterScript.Apply = 0;
                _context.MtdFilterScript.Update(mtdFilterScript);
                await _context.SaveChangesAsync();
            }

            return(Ok());
        }
예제 #2
0
        public async Task <IActionResult> PostFilterRemoveAllAsync()
        {
            IFormCollection requestForm = await Request.ReadFormAsync();

            string strID = requestForm["idFilter"];
            bool   isOk  = int.TryParse(strID, out int idFilter);

            if (!isOk)
            {
                return(NotFound());
            }

            IList <MtdFilterField> mtdFilterFields = await _context.MtdFilterField.Where(x => x.MtdFilter == idFilter).ToListAsync();

            IList <MtdFilterScript> mtdFilterScripts = await _context.MtdFilterScript
                                                       .Where(x => x.MtdFilter == idFilter)
                                                       .Select(x => new MtdFilterScript {
                Id = x.Id, MtdFilter = x.MtdFilter, Name = x.Name, Description = x.Description, Script = x.Script, Apply = 0
            })
                                                       .ToListAsync();

            MtdFilterDate mtdFilterDate = await _context.MtdFilterDate.Where(x => x.Id == idFilter).FirstOrDefaultAsync();

            try
            {
                _context.MtdFilterField.RemoveRange(mtdFilterFields);
                _context.MtdFilterScript.UpdateRange(mtdFilterScripts);
                if (mtdFilterDate != null)
                {
                    _context.MtdFilterDate.Remove(mtdFilterDate);
                }
                await _context.SaveChangesAsync();
            }
            catch (Exception ex) { throw ex.InnerException; }


            return(Ok());
        }
예제 #3
0
        public async Task <IViewComponentResult> InvokeAsync(string idForm)
        {
            List <DisplayData> displayDatas = new List <DisplayData>();
            var user = await _userHandler.GetUserAsync(HttpContext.User);

            List <string> partIds = await _userHandler.GetAllowPartsForView(user, idForm);

            MtdFilter filter = await _context.MtdFilter.FirstOrDefaultAsync(x => x.IdUser == user.Id && x.MtdForm == idForm);

            if (filter != null)
            {
                List <MtdFilterField> mtdFilterFields = await _context.MtdFilterField
                                                        .Include(x => x.MtdTermNavigation)
                                                        .Include(m => m.MtdFormPartFieldNavigation)
                                                        .Where(x => x.MtdFilter == filter.Id)
                                                        .ToListAsync();

                foreach (var field in mtdFilterFields)
                {
                    DisplayData displayData = new DisplayData
                    {
                        Id     = field.Id,
                        Header = $"{field.MtdFormPartFieldNavigation.Name} ({field.MtdTermNavigation.Sign})",
                        Value  = "",
                        Type   = "-field"
                    };

                    if (field.MtdFormPartFieldNavigation.MtdSysType != 11)
                    {
                        displayData.Value = field.Value;
                    }
                    else
                    {
                        MtdStore mtdStore = await _context.MtdStore.FirstOrDefaultAsync(x => x.Id == field.Value);

                        if (mtdStore != null)
                        {
                            var fieldForList = await _context.MtdFormPartField.Include(m => m.MtdFormPartNavigation)
                                               .Where(x => x.MtdFormPartNavigation.MtdForm == mtdStore.MtdForm & x.MtdSysType == 1)
                                               .OrderBy(o => o.MtdFormPartNavigation.Sequence).ThenBy(o => o.Sequence).FirstOrDefaultAsync();

                            if (fieldForList != null)
                            {
                                IList <long> ids = await _context.MtdStoreStack.Where(x => x.MtdStore == mtdStore.Id& x.MtdFormPartField == fieldForList.Id).Select(x => x.Id).ToListAsync();

                                MtdStoreStackText data = await _context.MtdStoreStackText.FirstOrDefaultAsync(x => ids.Contains(x.Id));

                                displayData.Value = data.Register;
                            }
                        }
                    }

                    displayDatas.Add(displayData);
                }

                MtdFilterDate mtdFilterDate = await _context.MtdFilterDate.FindAsync(filter.Id);

                if (mtdFilterDate != null)
                {
                    DisplayData displayDate = new DisplayData()
                    {
                        Id     = filter.Id,
                        Header = "Period",
                        Value  = $"{mtdFilterDate.DateStart.ToShortDateString()} {mtdFilterDate.DateEnd.ToShortDateString()}",
                        Type   = "-date"
                    };
                    displayDatas.Add(displayDate);
                }

                IList <MtdFilterScript> scripts = await _context.MtdFilterScript.Where(x => x.MtdFilter == filter.Id& x.Apply == 1).ToListAsync();

                if (scripts != null && scripts.Count > 0)
                {
                    foreach (var fs in scripts)
                    {
                        DisplayData displayDate = new DisplayData()
                        {
                            Id     = fs.Id,
                            Header = "Custom filter",
                            Value  = fs.Name,
                            Type   = "-script"
                        };
                        displayDatas.Add(displayDate);
                    }
                }
            }

            DisplayModelView displayModelView = new DisplayModelView
            {
                IdForm       = idForm,
                IdFilter     = filter == null ? -1 : filter.Id,
                DisplayDatas = displayDatas
            };

            return(View("Default", displayModelView));
        }
예제 #4
0
        public async Task <IActionResult> PostFilterAddAsync()
        {
            IFormCollection requestForm = await Request.ReadFormAsync();

            string valueField     = requestForm["indexInputField"];
            string idForm         = requestForm["indexInputForm"];
            string valueFilter    = requestForm["indexInputFilter"];
            string valueTerm      = requestForm["indexInputTerm"];
            string valueFieldList = requestForm[$"{valueField}-inputlist"];

            string result = "";

            if (valueFilter.FirstOrDefault() != null)
            {
                result = valueFilter;
            }
            if (valueFieldList.FirstOrDefault() != null)
            {
                result = valueFieldList;
            }

            WebAppUser user = await _userManager.GetUserAsync(User);

            MtdFilter filter = await _context.MtdFilter.FirstOrDefaultAsync(x => x.IdUser == user.Id& x.MtdForm == idForm);

            if (filter == null)
            {
                filter = new MtdFilter
                {
                    IdUser       = user.Id,
                    MtdForm      = idForm,
                    SearchNumber = "",
                    SearchText   = "",
                    Page         = 1,
                    PageSize     = 10
                };
                await _context.MtdFilter.AddAsync(filter);

                await _context.SaveChangesAsync();
            }

            if (valueField != "period")
            {
                await SaveFilterField(valueField, valueTerm, result, filter);
            }
            else
            {
                string dateStart  = requestForm["periodStart"];
                string dateFinish = requestForm["periodFinish"];

                bool isOkDateStart  = DateTime.TryParse(dateStart, out DateTime dateTimeStart);
                bool isOkDateFinish = DateTime.TryParse(dateFinish, out DateTime dateTimeFinish);

                if (isOkDateStart && isOkDateFinish)
                {
                    MtdFilterDate mtdFilterDate = new MtdFilterDate
                    {
                        Id        = filter.Id,
                        DateStart = dateTimeStart,
                        DateEnd   = dateTimeFinish
                    };

                    bool isExists = await _context.MtdFilterDate.Where(x => x.Id == filter.Id).AnyAsync();

                    if (isExists)
                    {
                        _context.MtdFilterDate.Update(mtdFilterDate);
                    }
                    else
                    {
                        await _context.MtdFilterDate.AddAsync(mtdFilterDate);
                    }

                    await _context.SaveChangesAsync();
                }
            }


            return(Ok());
        }