コード例 #1
0
        public async Task <ActionResult> SaveTemplate([FromHeader] int categoryId)
        {
            _iLogger.LogInformation("Attempting to save category template");


            var templateUser = await _categoriesRepository.GetTemplateUser();

            var category = new CategoryModel();

            category = await _categoriesRepository.GetCategoryItemsForClone(categoryId, templateUser.Id);

            category.Id = 0;
            category.CategoryGroupsModels.ForAll(u => u.Id = 0);
            category.CategoryGroupsModels.ForAll(u => u.CategoryItemsModels.ForAll(x => x.Id = 0));

            category.LoginModelId = (long)this.User.GetUserId();



            if (!await _categoriesRepository.CopyTemplateToUser(category, categoryId))
            {
                _iLogger.LogError("Unable to save template");
                return(BadRequest("Unable to update db"));
            }

            _iLogger.LogInformation("Template save successful");


            return(Ok());
        }