Exemple #1
0
        public IActionResult GetDefaultLayout(string entityName, [FromQuery] string type, string subtype, string context)
        {
            try {
                var stopwatch = StopwatchLogger.Start(_log);
                _log.Info("Called LayoutController GetLayoutsDetailsById");

                int    entitytype;
                var    contextType  = 0;
                string errormessage = "";

                if (string.IsNullOrEmpty(type))
                {
                    return(BadRequest("Type required."));
                }
                else
                {
                    try {
                        entitytype = _iMetadataManager.GetTypeId(type);
                    } catch (Exception ex) {
                        _log.Error(ExceptionFormatter.SerializeToString(ex));
                        return(BadRequest("Incorrect Type."));
                    }
                }

                if (entitytype == (int)LayoutType.Form)
                {
                    try {
                        contextType = _iMetadataManager.GetContextId(context);
                        if (contextType != (int)LayoutContext.QuickAdd)
                        {
                            if (string.IsNullOrEmpty(context))
                            {
                                errormessage += " Context required.";
                            }
                            if (string.IsNullOrEmpty(subtype))
                            {
                                errormessage += "Sub Type required.";
                            }
                        }
                    } catch (Exception ex) {
                        _log.Error(ExceptionFormatter.SerializeToString(ex));
                        return(BadRequest("Incorrect Context."));
                    }

                    // if (string.IsNullOrEmpty (subtype)) {
                    //     errormessage += "Sub Type required.";
                    // }
                    // else
                    // {
                    //     if(entityName == "user")
                    //         subtype = "Employee";
                    // }

                    // if (string.IsNullOrEmpty (context)) {
                    //     errormessage += " Context required.";
                    // } else {
                    //     try {
                    //         contextType = _iMetadataManager.GetContextId (context);
                    //     } catch (Exception ex) {
                    //         _log.Error (ExceptionFormatter.SerializeToString (ex));
                    //         return BadRequest ("Incorrect Context.");
                    //     }
                    // }

                    if (errormessage != "")
                    {
                        return(BadRequest(errormessage));
                    }
                }

                var layout = _iLayoutManager.GetDefaultLayoutForEntity(TenantCode, entityName, entitytype, subtype, contextType);
                //get all task configuration with entity name

                stopwatch.StopAndLog("GetLayoutsDetailsById of LayoutController");

                if (layout != null)
                {
                    return(_iJsonMessage.IgnoreNullableObject(layout));
                }
                return(NotFound("There is a configuration error. Default layout is missing for " + ((subtype != null) ? subtype + "." : entityName + ".")));
            } catch (Exception ex) {
                _log.Error(ExceptionFormatter.SerializeToString(ex));
                return(StatusCode((int)HttpStatusCode.InternalServerError, ApiConstant.CustomErrorMessage));
            }
        }