コード例 #1
0
        public async Task <JsonResult> ListFields(string documentId, string appId)
        {
            var appModule = await _appModuleRepository.Get(appId);

            if (appModule != null)
            {
                if (appModule.DocumentTypes == null)
                {
                    appModule.DocumentTypes = new List <DocumentType>();
                }


                var docService = new DocumentTypeServices(_appModuleRepository);
                var fields     = await docService.FindDocumentTypeFields(appId, ObjectId.Parse(documentId));

                var result = new JsonGenericResult
                {
                    IsSuccess = true,
                    Result    = fields
                };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            var errorResult = new JsonGenericResult
            {
                IsSuccess = true,
                Result    = appModule.DocumentTypes.FirstOrDefault(n => n.Id.ToString().ToLower().Trim() == documentId.ToLower().Trim()).Fields
            };

            return(Json(errorResult, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public async Task <JsonResult> GetSubDocuments(string documentId, string appId)
        {
            var parentDocumentTypes = new Dictionary <string, string>();
            var appModule           = await _appModuleRepository.Get(appId);

            if (appModule != null)
            {
                if (appModule.DocumentTypes == null)
                {
                    appModule.DocumentTypes = new List <DocumentType>();
                }

                if (appModule.DocumentTypes.Any(n => n.Id.ToString().ToLower().Trim() == documentId.ToLower().Trim()))
                {
                    var documentType = appModule.DocumentTypes.FirstOrDefault(n => n.Id.ToString().ToLower().Trim() == documentId.ToLower().Trim());
                    if (documentType.Fields != null)
                    {
                        if (documentType.Fields.Any())
                        {
                            parentDocumentTypes = GetAllDocumentTypes(documentType.Fields, parentDocumentTypes);
                        }
                    }
                }
            }


            var result = new JsonGenericResult
            {
                IsSuccess = true,
                Result    = appModule.DocumentTypes.FirstOrDefault(n => n.Id.ToString().ToLower().Trim() == documentId.ToLower().Trim()).Fields
            };

            return(Json(parentDocumentTypes, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public async Task <JsonResult> Create(AppModule model)
        {
            try
            {
                var userService = new UserService(_userRepository);
                var user        = await userService.Get(User.Identity.Name);

                if (!string.IsNullOrEmpty(user.CurrentOrganisation))
                {
                    var appModuleService = new AppModuleService(_appModuleRepository);
                    model.OrganisationId = user.CurrentOrganisation;
                    await appModuleService.Create(model);

                    var result = new JsonGenericResult
                    {
                        IsSuccess = true
                    };
                    return(Json(result));
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No current organisation. Please login into one."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #4
0
        public async Task <JsonResult> Add(DataPanel model)
        {
            try
            {
                var user = await _userRepository.GetUser(User.Identity.Name);

                if (!string.IsNullOrEmpty(user.CurrentOrganisation))
                {
                    model.OrganisationId = user.CurrentOrganisation;
                    await _dataPanelRepository.CreateSync(model);

                    var result = new JsonGenericResult
                    {
                        IsSuccess = true
                    };
                    return(Json(result));
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No current organisation. Please login into one."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #5
0
        public async Task <JsonResult> Create(ReqCreateDataView req)
        {
            try
            {
                if (!string.IsNullOrEmpty(req.AppModuleId))
                {
                    var appModule = await _appModuleRepository.Get(req.AppModuleId);

                    if (appModule != null)
                    {
                        if (appModule.DataViews == null)
                        {
                            appModule.DataViews = new List <DataView>();
                        }

                        ObjectId dataViewId = ObjectId.GenerateNewId();

                        var dataView = new DataView
                        {
                            Id             = dataViewId,
                            Name           = req.Name,
                            DataViewType   = req.DataViewType,
                            Description    = req.Description,
                            DocumentTypeId = ObjectId.Parse(req.DocumentTypeId)
                        };

                        if (!string.IsNullOrEmpty(req.SubDocumentTypeId))
                        {
                            dataView.SubDocumentTypeId = ObjectId.Parse(req.SubDocumentTypeId);
                        }

                        appModule.DataViews.Add(dataView);
                        await _appModuleRepository.Update(req.AppModuleId, appModule);

                        var result = new JsonGenericResult
                        {
                            IsSuccess = true,
                            Result    = dataViewId.ToString()
                        };
                        return(Json(result));
                    }
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #6
0
        public async Task <JsonResult> Create(ReqCreateDocumentType req)
        {
            try
            {
                if (!string.IsNullOrEmpty(req.AppModuleId))
                {
                    var appModule = await _appModuleRepository.Get(req.AppModuleId);

                    if (appModule != null)
                    {
                        if (appModule.DocumentTypes == null)
                        {
                            appModule.DocumentTypes = new List <DocumentType>();
                        }

                        if (appModule.DocumentTypes.Any(n => n.Name.ToLower().Trim() == req.Name.ToLower().Trim()))
                        {
                            var ErrorResult1 = new JsonGenericResult
                            {
                                IsSuccess = false,
                                Message   = "A document type of the same name already exists."
                            };
                            return(Json(ErrorResult1));
                        }
                        var docId = ObjectId.GenerateNewId();
                        appModule.DocumentTypes.Add(new DocumentType
                        {
                            Id          = docId,
                            Name        = req.Name,
                            Description = req.Description
                        });
                        await _appModuleRepository.Update(req.AppModuleId, appModule);

                        var result = new JsonGenericResult
                        {
                            IsSuccess = true,
                            Result    = docId.ToString()
                        };
                        return(Json(result));
                    }
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #7
0
        public async Task <JsonResult> GetDocumentTypes(string appModuleId, string parentId)
        {
            try
            {
                if (!string.IsNullOrEmpty(appModuleId))
                {
                    var appModule = await _appModuleRepository.Get(appModuleId);

                    if (appModule != null)
                    {
                        if (appModule.DocumentTypes != null)
                        {
                            if (parentId == "0")
                            {
                                var resultRoot = new JsonGenericResult
                                {
                                    IsSuccess = true,
                                    Result    = appModule.DocumentTypes
                                };
                                return(Json(resultRoot, JsonRequestBehavior.AllowGet));
                            }
                            var result = new JsonGenericResult
                            {
                                IsSuccess = true,
                                Result    = appModule.DocumentTypes
                            };
                            return(Json(result, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            var emptyResult = new JsonGenericResult
                            {
                                IsSuccess = true,
                                Result    = new List <DocumentType>()
                            };
                            return(Json(emptyResult, JsonRequestBehavior.AllowGet));
                        }
                    }
                }
                var noAppResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(noAppResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #8
0
        public async Task <JsonResult> AddDropdown(ReqAddDropdown req)
        {
            try
            {
                if (!string.IsNullOrEmpty(req.AppId))
                {
                    var appModule = await _appModuleRepository.Get(req.AppId);

                    if (appModule != null)
                    {
                        if (appModule.Dropdowns == null)
                        {
                            appModule.Dropdowns = new List <Dropdown>();
                        }

                        var dropdownId  = ObjectId.GenerateNewId();
                        var newDropdown = new Dropdown
                        {
                            AppModuleId = appModule.Id,
                            Id          = dropdownId,
                            Name        = req.Name,
                            Items       = req.Items
                        };

                        appModule.Dropdowns.Add(newDropdown);

                        await _appModuleRepository.Update(req.AppId, appModule);

                        var result = new JsonGenericResult
                        {
                            IsSuccess = true,
                            Result    = dropdownId.ToString()
                        };
                        return(Json(result));
                    }
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #9
0
        public async Task <JsonResult> AddEvent(ReqAddEvent req)
        {
            try
            {
                var user = await _userRepository.GetUser(User.Identity.Name);

                if (user != null)
                {
                    var calendarEvent = new CalendarEvent
                    {
                        CreateByUserId = user.Id,
                        Title          = req.Event.Title,
                        Details        = req.Event.Details,
                        StartDate      = req.Event.StartDate,
                        EndDate        = req.Event.EndDate,
                        EventType      = req.Event.EventType
                    };
                    if (req.Event.EventType.ToLower() == "personal")
                    {
                        calendarEvent.ForeignId = user.Id;
                    }
                    else
                    {
                        calendarEvent.ForeignId = ObjectId.Parse(user.CurrentOrganisation);
                    }
                    await _calendarEventRepository.CreateSync(calendarEvent);

                    var result = new JsonGenericResult
                    {
                        IsSuccess = true,
                        Result    = calendarEvent.Id
                    };
                    return(Json(result));
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "Error adding event."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #10
0
        public async Task <JsonResult> FetchData(ReqData req)
        {
            var appModule = await _appModuleRepository.Get(req.AppId);

            var docTypeService = new DocumentTypeServices(_appModuleRepository);

            ObjectId documentTypeId;

            ObjectId.TryParse(req.DocumentTypeId, out documentTypeId);

            var documentName = await docTypeService.FindDocumentTypeName(req.AppId, documentTypeId);

            var rootDocumentName = documentName;
            var org = await _organisationRepository.Get(appModule.OrganisationId);

            var dataService = new DataService(ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString, org.Id.ToString(), documentName);
            //var data = await dataService.Get(dataId, "");

            BsonDocument data;

            if (!string.IsNullOrEmpty(req.SubDocumentTypeId))
            {
                ObjectId subDocumentTypeId;
                ObjectId.TryParse(req.SubDocumentTypeId, out subDocumentTypeId);
                documentName = await docTypeService.FindDocumentTypeName(req.AppId, subDocumentTypeId);

                var subDocumentHierarchy = await docTypeService.FindSubDocumentHierarchy(req.AppId, documentTypeId, documentName, rootDocumentName);

                data = await dataService.Get(req.DataId, subDocumentHierarchy);
            }
            else
            {
                data = await dataService.Get(req.DataId);
            }

            var jsonWriterSettings = new JsonWriterSettings {
                OutputMode = JsonOutputMode.Strict
            };

            var result = new JsonGenericResult
            {
                IsSuccess = true,
                Result    = data.ToJson(jsonWriterSettings)
            };

            return(Json(result));
        }
コード例 #11
0
        public async Task <JsonResult> Details(string eventId)
        {
            var eventDetails = await _calendarEventRepository.Get(eventId);

            if (eventDetails != null)
            {
                var result = new JsonGenericResult
                {
                    IsSuccess = true,
                    Result    = eventDetails
                };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            var ErrorResult = new JsonGenericResult
            {
                IsSuccess = false,
                Message   = "Error."
            };

            return(Json(ErrorResult));
        }
コード例 #12
0
        public async Task <JsonResult> AddPage(ReqAddPage req)
        {
            try
            {
                var module = await _appModuleRepository.Get(req.ModuleId);

                if (module != null)
                {
                    req.Page.PageId = ObjectId.GenerateNewId();
                    if (module.Pages == null)
                    {
                        module.Pages = new List <AppModulePage>();
                    }

                    module.Pages.Add(req.Page);
                    await _appModuleRepository.Update(module.Id.ToString(), module);

                    var result = new JsonGenericResult
                    {
                        IsSuccess = true
                    };
                    return(Json(result));
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "Module cannot be found."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #13
0
        public async Task <JsonResult> List(string appId)
        {
            try
            {
                if (!string.IsNullOrEmpty(appId))
                {
                    var appModule = await _appModuleRepository.Get(appId);

                    if (appModule != null)
                    {
                        if (appModule.Pages == null)
                        {
                            appModule.Pages = new List <AppModulePage>();
                        }
                        var result = new JsonGenericResult
                        {
                            IsSuccess = true,
                            Result    = appModule.Pages
                        };
                        return(Json(result, JsonRequestBehavior.AllowGet));
                    }
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "Module cannot be found."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                var ErrorResult1 = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = ex.Message
                };
                return(Json(ErrorResult1));
            }
        }
コード例 #14
0
        public async Task <JsonResult> ListForms(string appId)
        {
            try
            {
                if (!string.IsNullOrEmpty(appId))
                {
                    var appModule = await _appModuleRepository.Get(appId);

                    if (appModule != null)
                    {
                        if (appModule.Forms == null)
                        {
                            appModule.Forms = new List <ModuleForm>();
                        }
                        var result = new JsonGenericResult
                        {
                            IsSuccess = true,
                            Result    = appModule.Forms
                        };
                        return(Json(result, JsonRequestBehavior.AllowGet));
                    }
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #15
0
        public async Task <JsonResult> AddUser(RegisterViewModel model)
        {
            try
            {
                if (model.Password == model.PasswordRepeat)
                {
                    var userService = new UserService(_userRepository);
                    var user        = new User
                    {
                        Email     = model.Username,
                        FirstName = model.FirstName,
                        LastName  = model.LastName,
                        Password  = model.Password
                    };
                    var newUser = await userService.CreateUser(user);

                    var result = new JsonGenericResult
                    {
                        IsSuccess = true
                    };
                    return(Json(result));
                }
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = "Password does not match."
                }));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #16
0
        public async Task <JsonResult> Create(Organisation model)
        {
            try
            {
                var organisationService = new OrganisationService(_organisationRepository, _userRepository);
                model.Users = new List <string>();
                model.Users.Add(User.Identity.Name);
                await organisationService.CreateAndSetUserDefaultOrganisation(model, User.Identity.Name);

                var result = new JsonGenericResult
                {
                    IsSuccess = true
                };
                return(Json(result));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #17
0
        public async Task <JsonResult> AddField(ReqAddField req)
        {
            try
            {
                var app = await _appModuleRepository.Get(req.AppId);

                if (app != null)
                {
                    if (app.DocumentTypes != null)
                    {
                        if (app.DocumentTypes.Any(n => n.Id.ToString() == req.DocumentTypeId))
                        {
                            var documentType = app.DocumentTypes.FirstOrDefault(n => n.Id.ToString() == req.DocumentTypeId);
                            if (documentType != null)
                            {
                                if (documentType.Fields == null)
                                {
                                    documentType.Fields = new List <Field>();
                                }
                                if (documentType.Fields.Any(n => n.Name.ToLower().Trim() == req.Name))
                                {
                                    throw new Exception("Field name already exist!");
                                }
                                var fieldId = ObjectId.GenerateNewId();
                                if (req.Parent == "0")
                                {
                                    documentType.Fields.Add(new Field
                                    {
                                        Id       = fieldId,
                                        Name     = req.Name,
                                        DataType = req.DataType
                                    });
                                }
                                else
                                {
                                    FindDocumentType(ObjectId.Parse(req.Parent), documentType.Fields, req.Name, req.DataType);
                                }
                                await _appModuleRepository.Update(req.AppId, app);

                                var result = new JsonGenericResult
                                {
                                    IsSuccess = true,
                                    Result    = fieldId
                                };
                                return(Json(result));
                            }
                        }
                    }
                }

                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #18
0
        public async Task <JsonResult> Create(ReqCreateForm req)
        {
            try
            {
                if (!string.IsNullOrEmpty(req.AppModuleId))
                {
                    var appModule = await _appModuleRepository.Get(req.AppModuleId);

                    if (appModule != null)
                    {
                        if (appModule.Forms == null)
                        {
                            appModule.Forms = new List <ModuleForm>();
                        }

                        ObjectId documentTypeId;
                        ObjectId appModuleId;

                        if (ObjectId.TryParse(req.AppModuleId, out appModuleId) && ObjectId.TryParse(req.DocumentTypeId, out documentTypeId))
                        {
                            if (appModule.Forms.Any(n => n.Name.ToLower().Trim() == req.Name.ToLower().Trim()))
                            {
                                var ErrorResult1 = new JsonGenericResult
                                {
                                    IsSuccess = false,
                                    Message   = "A Form of the same name already exists."
                                };
                                return(Json(ErrorResult1));
                            }
                            var formId  = ObjectId.GenerateNewId();
                            var newForm = new ModuleForm
                            {
                                Id                = formId,
                                Name              = req.Name,
                                Description       = req.Description,
                                DocumentTypeId    = documentTypeId,
                                SubDocumentTypeId = null
                            };

                            if (!string.IsNullOrEmpty(req.SubDocumentTypeId))
                            {
                                ObjectId subDocumentTypeId;
                                if (ObjectId.TryParse(req.SubDocumentTypeId, out subDocumentTypeId))
                                {
                                    newForm.SubDocumentTypeId = subDocumentTypeId;
                                }
                            }

                            appModule.Forms.Add(newForm);
                            await _appModuleRepository.Update(req.AppModuleId, appModule);

                            var result = new JsonGenericResult
                            {
                                IsSuccess = true,
                                Result    = formId.ToString()
                            };
                            return(Json(result));
                        }
                        var ErrorResult2 = new JsonGenericResult
                        {
                            IsSuccess = false,
                            Message   = "Invalid app module id or document type id."
                        };
                        return(Json(ErrorResult2));
                    }
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #19
0
        public async Task <JsonResult> AddFormField(ReqAddFormField req)
        {
            try
            {
                if (!string.IsNullOrEmpty(req.AppModuleId))
                {
                    var appModule = await _appModuleRepository.Get(req.AppModuleId);

                    if (appModule != null)
                    {
                        if (appModule.Forms == null)
                        {
                            appModule.Forms = new List <ModuleForm>();
                        }

                        ObjectId formId;
                        ObjectId appModuleId;

                        if (ObjectId.TryParse(req.AppModuleId, out appModuleId) && ObjectId.TryParse(req.FormId, out formId))
                        {
                            if (appModule.Forms.Any(n => n.Id == formId))
                            {
                                var formFieldId = ObjectId.GenerateNewId();

                                var form = appModule.Forms.FirstOrDefault(n => n.Id == formId);
                                if (form.Fields == null)
                                {
                                    form.Fields = new List <FormField>();
                                }

                                var newFormField = new FormField
                                {
                                    Id       = formFieldId,
                                    FieldId  = ObjectId.Parse(req.FieldId),
                                    Order    = req.Order,
                                    ColWidth = req.ColWidth
                                };
                                form.Fields.Add(newFormField);

                                await _appModuleRepository.Update(req.AppModuleId, appModule);

                                var result = new JsonGenericResult
                                {
                                    IsSuccess = true,
                                    Result    = formFieldId.ToString()
                                };
                                return(Json(result));
                            }
                        }
                        var ErrorResult2 = new JsonGenericResult
                        {
                            IsSuccess = false,
                            Message   = "Invalid app module id or document type id."
                        };
                        return(Json(ErrorResult2));
                    }
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #20
0
        public async Task <JsonResult> Insert(ReqAddData req)
        {
            try
            {
                if (!string.IsNullOrEmpty(req.appId))
                {
                    var appModule = await _appModuleRepository.Get(req.appId);

                    if (appModule != null)
                    {
                        if (appModule.Forms == null)
                        {
                            appModule.Forms = new List <ModuleForm>();
                        }

                        ObjectId formId;
                        if (ObjectId.TryParse(req.foreignId, out formId))
                        {
                            var form   = appModule.Forms.FirstOrDefault(n => n.Id == formId);
                            var result = new JsonGenericResult
                            {
                                IsSuccess = true,
                                Result    = form
                            };

                            var org = await _organisationRepository.Get(appModule.OrganisationId);

                            var docTypeService = new DocumentTypeServices(_appModuleRepository);
                            var documentName   = await docTypeService.FindDocumentTypeName(req.appId, form.DocumentTypeId);

                            var parentDocumentName = documentName == req.ParentDocumentName ? "" : req.ParentDocumentName;


                            var dataService = new DataService(ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString, org.Id.ToString(), documentName);
                            var serializer  = new JavaScriptSerializer();

                            if (form.SubDocumentTypeId != null && form.SubDocumentTypeId != ObjectId.Empty)
                            {
                                var subDocumentName = await docTypeService.FindDocumentTypeName(req.appId, form.SubDocumentTypeId.Value);

                                var rootDocumentName = await docTypeService.FindDocumentTypeName(req.appId, form.DocumentTypeId);

                                var parentHeirarchy = await docTypeService.FindSubDocumentHierarchy(req.appId, form.DocumentTypeId, subDocumentName, rootDocumentName);

                                parentHeirarchy = parentHeirarchy.Replace(subDocumentName, "");
                                if (parentHeirarchy.Length > 1)
                                {
                                    if (parentHeirarchy.Substring(parentHeirarchy.Length - 1, 1) == ".")
                                    {
                                        parentHeirarchy = parentHeirarchy.Substring(0, parentHeirarchy.Length - 1);
                                    }
                                }

                                //await dataService.Add(req.data, req.RootDataId, subDocumentName, parentDocumentName);
                                await dataService.Add(req.data, req.RootDataId, subDocumentName, parentHeirarchy);
                            }
                            else
                            {
                                dataService.Add(req.data);
                            }

                            return(Json(result));
                        }
                    }
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }
コード例 #21
0
        public async Task <JsonResult> TabularAddColumn(ReqTabularAddColumn req)
        {
            if (!string.IsNullOrEmpty(req.AppId))
            {
                var columnId  = string.Empty;
                var appModule = await _appModuleRepository.Get(req.AppId);

                if (appModule != null)
                {
                    if (appModule.Forms != null)
                    {
                        ViewBag.AppId   = appModule.Id.ToString();
                        ViewBag.AppName = appModule.Name;

                        ObjectId dataViewId;
                        if (ObjectId.TryParse(req.DataViewId, out dataViewId))
                        {
                            if (appModule.DataViews.Any(n => n.Id == dataViewId))
                            {
                                var dataView     = appModule.DataViews.FirstOrDefault(n => n.Id == dataViewId);
                                var dataColumnId = ObjectId.GenerateNewId();
                                if (dataView.Tabular == null)
                                {
                                    dataView.Tabular = new Tabular();
                                }
                                if (dataView.Tabular.Columns == null)
                                {
                                    dataView.Tabular.Columns = new List <TabularColumns>();
                                }
                                var tabularColumn = new TabularColumns
                                {
                                    Id                 = dataColumnId,
                                    FieldId            = ObjectId.Parse(req.FieldId),
                                    Order              = req.Order,
                                    IsLinkToDetailPage = req.IsLinkToDetailPage
                                };
                                if (req.IsLinkToDetailPage)
                                {
                                    tabularColumn.PageId = ObjectId.Parse(req.PageId);
                                }

                                dataView.Tabular.Columns.Add(tabularColumn);

                                await _appModuleRepository.Update(req.AppId, appModule);

                                columnId = dataColumnId.ToString();
                            }
                        }
                    }
                    var result = new JsonGenericResult
                    {
                        IsSuccess = true,
                        Result    = columnId
                    };
                    return(Json(result));
                }
            }
            var ErrorResult = new JsonGenericResult
            {
                IsSuccess = false,
                Message   = "No app selected."
            };

            return(Json(ErrorResult));
        }
コード例 #22
0
        public async Task <JsonResult> DetailAddComponent(ReqDetailAddComponent req)
        {
            if (!string.IsNullOrEmpty(req.AppId))
            {
                var columnId  = string.Empty;
                var appModule = await _appModuleRepository.Get(req.AppId);

                if (appModule != null)
                {
                    if (appModule.Forms != null)
                    {
                        ViewBag.AppId   = appModule.Id.ToString();
                        ViewBag.AppName = appModule.Name;

                        ObjectId dataViewId;
                        if (ObjectId.TryParse(req.DataViewId, out dataViewId))
                        {
                            if (appModule.DataViews.Any(n => n.Id == dataViewId))
                            {
                                var dataView    = appModule.DataViews.FirstOrDefault(n => n.Id == dataViewId);
                                var componentId = ObjectId.GenerateNewId();
                                if (dataView.Detail == null)
                                {
                                    dataView.Detail = new Detail();
                                }
                                if (dataView.Detail.Components == null)
                                {
                                    dataView.Detail.Components = new List <DetailComponent>();
                                }

                                ObjectId?fieldId = null;
                                if (req.ComponentType.Contains("Data"))
                                {
                                    ObjectId fieldIdContainer;
                                    if (ObjectId.TryParse(req.FieldId, out fieldIdContainer))
                                    {
                                        fieldId = fieldIdContainer;
                                    }
                                }

                                dataView.Detail.Components.Add(new DetailComponent
                                {
                                    ColWidth      = req.ColWidth,
                                    ComponentType = req.ComponentType,
                                    FieldId       = fieldId,
                                    Order         = req.Order,
                                    Text          = req.Text,
                                    Id            = componentId
                                });

                                await _appModuleRepository.Update(req.AppId, appModule);

                                columnId = componentId.ToString();
                            }
                        }
                    }
                    var result = new JsonGenericResult
                    {
                        IsSuccess = true,
                        Result    = columnId
                    };
                    return(Json(result));
                }
            }
            var ErrorResult = new JsonGenericResult
            {
                IsSuccess = false,
                Message   = "No app selected."
            };

            return(Json(ErrorResult));
        }
コード例 #23
0
        public async Task <JsonResult> FetchListData(ReqData req)
        {
            var appModule = await _appModuleRepository.Get(req.AppId);

            var docTypeService = new DocumentTypeServices(_appModuleRepository);

            ObjectId documentTypeId;

            ObjectId.TryParse(req.DocumentTypeId, out documentTypeId);

            var documentName = await docTypeService.FindDocumentTypeName(req.AppId, documentTypeId);

            var org = await _organisationRepository.Get(appModule.OrganisationId);

            var dataService = new DataService(ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString, org.Id.ToString(), documentName);
            //var data = await dataService.Get(dataId, "");

            Object data = null;

            //if (!string.IsNullOrEmpty(req.SubDocumentTypeId))
            //{
            //    ObjectId subDocumentTypeId;
            //    ObjectId.TryParse(req.SubDocumentTypeId, out subDocumentTypeId);
            //    documentName = await docTypeService.FindDocumentTypeName(req.AppId, subDocumentTypeId);
            //    data = await dataService.Get(req.DataId, documentName);
            //}
            //else
            //{
            //    data = await dataService.ListAll();
            //}

            var jsonWriterSettings = new JsonWriterSettings {
                OutputMode = JsonOutputMode.Strict
            };

            if (!string.IsNullOrEmpty(req.SubDocumentTypeId))
            {
                if (req.DataId != null)
                {
                    ObjectId subDocumentTypeId;
                    ObjectId.TryParse(req.SubDocumentTypeId, out subDocumentTypeId);
                    var subDocumentName = await docTypeService.FindDocumentTypeName(req.AppId, subDocumentTypeId);

                    var parentSubDocumentName = await docTypeService.FindParentDocumentTypeName(req.AppId, documentTypeId, subDocumentName);

                    var suDocData = await dataService.ListAll(ObjectId.Parse(req.DataId), subDocumentName, parentSubDocumentName);

                    data = suDocData;
                }
            }
            else
            {
                data = await dataService.ListAll();
            }


            var result = new JsonGenericResult
            {
                IsSuccess = true,
                Result    = data.ToJson(jsonWriterSettings)
            };

            return(Json(result));
        }
コード例 #24
0
        public async Task <JsonResult> AddPanel(ReqAddPanel req)
        {
            try
            {
                if (!string.IsNullOrEmpty(req.AppModuleId))
                {
                    var appModule = await _appModuleRepository.Get(req.AppModuleId);

                    if (appModule != null)
                    {
                        if (appModule.Forms == null)
                        {
                            appModule.Forms = new List <ModuleForm>();
                        }

                        ObjectId pageId;
                        ObjectId appModuleId;

                        if (ObjectId.TryParse(req.AppModuleId, out appModuleId) && ObjectId.TryParse(req.PageId, out pageId))
                        {
                            if (appModule.Pages.Any(n => n.PageId == pageId))
                            {
                                var panelId = ObjectId.GenerateNewId();

                                var page = appModule.Pages.FirstOrDefault(n => n.PageId == pageId);
                                if (page.Panels == null)
                                {
                                    page.Panels = new List <PagePanel>();
                                }

                                var newPagePanel = new PagePanel
                                {
                                    Id        = pageId,
                                    ColWidth  = req.Panel.ColWidth,
                                    Order     = req.Panel.Order,
                                    PanelType = req.Panel.PanelType,
                                    ForeignId = ObjectId.Parse(req.ForeignId)
                                };
                                page.Panels.Add(newPagePanel);

                                await _appModuleRepository.Update(req.AppModuleId, appModule);

                                var result = new JsonGenericResult
                                {
                                    IsSuccess = true,
                                    Result    = panelId.ToString()
                                };
                                return(Json(result));
                            }
                        }
                        var ErrorResult2 = new JsonGenericResult
                        {
                            IsSuccess = false,
                            Message   = "Invalid app module id or document type id."
                        };
                        return(Json(ErrorResult2));
                    }
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "No app selected."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }