/// <summary> /// The method for initialize needed modules. /// </summary> /// <param name="app"> IApplicationBuilder </param> public static void InitModules(IApplicationBuilder app) { initStore = new InitStore("Canvas"); store = initStore.GetStore(); userRepository = new UserRepository(store); canvasRepository = new CanvasRepository(store); canvasTemplateRepository = new CanvasTemplateRepository(store); authRepository = new AuthRepository(store); userService = new UserService(userRepository); canvasService = new CanvasService(canvasTemplateRepository, store); authService = new AuthService(store); canvasTemplateService = new CanvasTemplateService(store); pdfCreater = new PdfCreater(); }
/// <summary> /// The method for creating a new canvas. /// </summary> /// <param name="data"> Information about canvas like title, type, etc. </param> /// <returns> Id of the new created canvas. </returns> public string CreateCanvas(CreateCanvasData data) { string ownerId = data.ownerId, title = data.title, type = data.type; // Get a template of canvas of the requested type from database (canvas template collection). Models.Canvas canvas = CanvasTemplateRepository.GetCanvasTemplateByType(type); canvas._id = ""; canvas.ownerId = ownerId; canvas.title = title; /// <summary> /// Try to insert a new canvas to database. /// </summary> try { Collection.InsertOne(canvas); return($"{{\"id\": \"{canvas._id}\"}}"); } catch { return($"{{\"error\": \"Something went wrong\"}}"); } }