public async Task <IActionResult> GetAllRecords(string model, int pageNo = 1, int pageSize = Globals.AdminDefaultPageCount, string orderBy = null)
        {
            try
            {
                ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);
                var modelType = coreAdminService.GetModelType(model);
                if (modelType == null)
                {
                    return(BadRequest($"Model {model} is not found"));
                }

                var result = await coreAdminService.GetAllFor(modelType, pageNo, pageSize, orderBy); //_adminRepository.GetAllFor(model, pageNo, pageSize, orderBy);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error occured while getting all records for model: {model}", ex);
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <IActionResult> Delete(string model, string id)
        {
            try
            {
                ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);
                var modelType = coreAdminService.GetModelType(model);
                if (modelType == null)
                {
                    return(BadRequest($"Model {model} is not found"));
                }

                var result = await coreAdminService.DeleteItemFor(modelType, id); //_adminRepository.DeleteItemFor(model, id);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error occured while deleting a record for model: {model}, id:{id}", ex);
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <IActionResult> ExecuteCustomFormAction(string model, string formName, string actionName, [FromBody] object modelObject)
        {
            try
            {
                ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);
                var modelType = coreAdminService.GetModelType(model);
                if (modelType == null)
                {
                    return(BadRequest($"Model {model} is not found"));
                }

                var result = await coreAdminService.ExecuteCustomFormAction(modelType, formName, actionName, modelObject); //_adminRepository.UpdateItemFor(model, fieldObject);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error occured while executing custom action {actionName} for model: {model}", ex);
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <IActionResult> SortItems(string model, string childModel, [FromBody] object modelObject, int pageNo = 1, int pageSize = Globals.AdminDefaultPageCount)
        {
            try
            {
                ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);

                var modelType = coreAdminService.GetModelType(model);
                if (modelType == null)
                {
                    return(BadRequest($"Model {model} is not found"));
                }

                var result = await coreAdminService.SortItemsFor(modelType, pageNo, pageSize, modelObject, childModel); //_adminRepository.UpdateItemFor(model, fieldObject);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error occured while sorting items for model: {model}", ex);
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <IActionResult> AutoFill(string model, string fieldName, [FromBody] dynamic modelObject)
        {
            try
            {
                ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);
                var modelType = coreAdminService.GetModelType(model);
                if (modelType == null)
                {
                    return(BadRequest($"Model {model} is not found"));
                }

                var result = await coreAdminService.AutoFill(modelType, fieldName, modelObject.fieldValue); //_adminRepository.UpdateItemFor(model, fieldObject);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error occured while autofilling for model: {model}, fieldName: {fieldName}", ex);
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <IActionResult> GetTree(string model)
        {
            try
            {
                ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);
                var modelType = coreAdminService.GetModelType(model);
                if (modelType == null)
                {
                    return(BadRequest($"Model {model} is not found"));
                }

                var result = await coreAdminService.GetTree(modelType);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error occured while getting tree for model: {model}", ex);
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <IActionResult> CustomValidate(string model, string formType, string formName, string fieldName, [FromBody] object fieldObject)
        {
            try
            {
                ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);
                var modelType = coreAdminService.GetModelType(model);
                if (modelType == null)
                {
                    return(BadRequest($"Model {model} is not found"));
                }

                if (string.IsNullOrEmpty(formType))
                {
                    return(BadRequest($"formType is required"));
                }

                if (formType == "MainForm")
                {
                    var result = await coreAdminService.ExecuteMainFormCustomValidation(modelType, fieldName, fieldObject);

                    if (result != null)
                    {
                        return(Ok(result));
                    }
                }

                if (string.IsNullOrEmpty(formName))
                {
                    return(BadRequest($"formName is required for ChildForm and CustomForm"));
                }


                if (formType == "ChildForm")
                {
                    var result = await coreAdminService.ExecuteChildFormCustomValidation(modelType, formName, fieldName, fieldObject);

                    if (result != null)
                    {
                        return(Ok(result));
                    }
                }
                else //if (formType == "CustomForm")
                {
                    var result = await coreAdminService.ExecuteCustomFormCustomValidation(modelType, formName, fieldName, fieldObject);

                    if (result != null)
                    {
                        return(Ok(result));
                    }
                }

                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error occured while executing custom validation for fieldName: {fieldName} in model: {model}", ex);
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
        public async Task <IActionResult> GetLookupFor(string model, string formType, string formName, string fieldName,
                                                       [FromBody] object filterParam)
        {
            ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);
            var modelType = coreAdminService.GetModelType(model);

            if (modelType == null)
            {
                return(BadRequest($"Model {model} is not found"));
            }

            if (string.IsNullOrEmpty(formType))
            {
                return(BadRequest($"formType is required"));
            }

            if (formType == "MainForm")
            {
                var result = await coreAdminService.GetLookUpForMainForm(modelType, fieldName, filterParam);

                if (result != null)
                {
                    return(Ok(result));
                }
            }

            if (string.IsNullOrEmpty(formName))
            {
                return(BadRequest($"formName is required for ChildForm and CustomForm"));
            }

            if (formType == "ChildForm")
            {
                var result = await coreAdminService.GetLookUpForChildForm(modelType, formName, fieldName, filterParam);

                if (result != null)
                {
                    return(Ok(result));
                }
            }
            else //if (formType == "CustomForm")
            {
                var result = await coreAdminService.GetLookUpForCustomForm(modelType, formName, fieldName, filterParam);

                if (result != null)
                {
                    return(Ok(result));
                }
            }

            return(NotFound());
        }
 public IActionResult GetMetaInfo(string model)
 {
     try
     {
         ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);
         var adminConfig = coreAdminService.GetAdminConfig(model); //_adminRepository.GetAdminConfig(model);
         if (adminConfig != null)
         {
             return(Ok(adminConfig));
         }
         return(NotFound());
     }
     catch (Exception ex)
     {
         _logger.LogError($"Error occured while getting meta info for model: {model}", ex);
         return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
     }
 }
 public IActionResult Admin(string model)
 {
     try
     {
         ICoreAdminService coreAdminService = new CoreAdminService(Area, _serviceProvider);
         var adminConfig = coreAdminService.GetAdminConfig(model); //_adminRepository.GetAdminConfig(model);
         if (adminConfig != null)
         {
             ViewBag.AdminConfig = adminConfig;
         }
         ViewBag.Model = model;
         return(View());
     }
     catch (Exception ex)
     {
         _logger.LogError($"Error occured while getting loading admin: {model}", ex);
         return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
     }
 }