示例#1
0
        public async Task <IActionResult> Edit(Guid id)
        {
            var viewModelRequest = await _viewModelService.GetViewModelByIdAsync(id);

            if (!viewModelRequest.IsSuccess)
            {
                return(NotFound());
            }
            return(View(viewModelRequest.Result));
        }
示例#2
0
        public async Task <JsonResult> LoadPagedData(DTParameters param, Guid viewModelId, ICollection <Filter> filters)
        {
            var response = new DTResult <object>
            {
                Data = new List <object>(),
                Draw = param.Draw
            };

            if (viewModelId == Guid.Empty)
            {
                return(Json(response));
            }
            var viewModelRequest = await _viewModelService.GetViewModelByIdAsync(viewModelId);

            if (!viewModelRequest.IsSuccess)
            {
                return(Json(response));
            }
            var viewModel = viewModelRequest.Result;

            if (viewModel == null)
            {
                return(Json(response));
            }
            var orderConf = new Dictionary <string, EntityOrderDirection>();

            if (param.Order?.Any() ?? false)
            {
                foreach (var order in param.Order)
                {
                    var field = viewModel.ViewModelFields.FirstOrDefault(x => x.Order == order.Column - 1);
                    if (field != null)
                    {
                        orderConf.Add(field.TableModelFields?.Name ?? field.Name, (EntityOrderDirection)order.Dir);
                    }
                }
            }
            else
            {
                orderConf.Add(nameof(BaseModel.Created), EntityOrderDirection.Desc);
            }

            var page            = param.Start / param.Length + 1;
            var pageDataRequest = await _service.GetPaginatedResultAsync(viewModel.TableModel.Name, (uint)page,
                                                                         (uint)param.Length, param.Search.Value, filters, orderConf);

            if (pageDataRequest.IsSuccess)
            {
                var final = (await LoadManyToManyReferences(pageDataRequest.Result.ViewModel.Values.ToList(), viewModel)).ToList();
                response.Data            = final;
                response.RecordsTotal    = final.Count;
                response.RecordsFiltered = (int)pageDataRequest.Result.Total;
            }

            var serializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                DateFormatString = GearSettings.Date.DateFormat
            };

            return(Json(response, serializerSettings));
        }