/// <summary> /// Get input select values /// </summary> /// <param name="fieldId"></param> /// <returns></returns> public async Task <JsonResult> GetInputSelectValues(Guid fieldId) { if (Guid.Empty == fieldId) { return(Json(new ResultModel())); } var field = _pagesContext.TableFields.FirstOrDefault(x => x.Id.Equals(fieldId)); if (field == null) { return(Json(new ResultModel())); } var config = await _pagesContext.TableFieldConfigValues .Include(x => x.TableFieldConfig) .ThenInclude(x => x.TableFieldType) .FirstOrDefaultAsync(x => x.TableModelFieldId.Equals(fieldId) && x.TableFieldConfig.Code == TableFieldConfigCode.Reference.ForeingTable); if (config == null) { return(Json(new ResultModel())); } if (!config.TableFieldConfig.TableFieldType.Name.Equals("EntityReference")) { return(Json(new ResultModel())); } var table = config.Value; var instance = _service.Table(table); return(Json(await instance.GetAllWithInclude <object>(filters: new List <Filter> { new Filter { Value = false, Criteria = Criteria.Equals, Parameter = nameof(BaseModel.IsDeleted) } }))); }
public async Task <JsonResult> DeleteItemFromDynamicEntity(Guid viewModelId, string id) { var result = new ResultModel(); if (string.IsNullOrEmpty(id) || viewModelId == Guid.Empty) { result.Errors.Add(new ErrorModel("", "Fail to delete!")); return(Json(result)); } var viewModel = await _pagesContext.ViewModels.Include(x => x.TableModel).FirstOrDefaultAsync(x => x.Id.Equals(viewModelId)); if (viewModel == null) { return(Json(result)); } var response = await _service.Table(viewModel.TableModel.Name).Delete <object>(Guid.Parse(id)); if (!response.IsSuccess) { return(Json(result)); } result.IsSuccess = true; return(Json(result)); }
public async Task <JsonResult> UpdateAsync([Required][FromBody] RequestData data) { if (data == null) { return(RequestData.InvalidRequest); } var result = new ResultModel(); var operationalTable = _dynamicService.Table(data.EntityName); try { var parsed = JsonConvert.DeserializeObject(data.Object, operationalTable.Type, SerializerSettings); var rq = await operationalTable.Update(parsed); return(Json(rq)); } catch (JsonSerializationException e) { result.Errors.Add(new ErrorModel(nameof(JsonSerializationException), e.Message)); } catch (Exception e) { result.Errors.Add(new ErrorModel(nameof(Exception), e.ToString())); } return(new JsonResult(result)); }