コード例 #1
0
        public async Task SaveCategory(Category category)
        {
            Category result = Categories.AsQueryable().FirstOrDefault<Category>(x => x.Id == category.Id);
            if (result != null)
                await Categories.FindOneAndReplaceAsync(x => x.Id == category.Id, category);
            else
                await Categories.InsertOneAsync(category);

        }
コード例 #2
0
        public async Task<IActionResult> EditCategory(CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                Category result = null;
                //load category if available
                if (string.IsNullOrEmpty(model.ObjectId) == false)
                {
                    result = _categoryService.GetCategoryById(new MongoDB.Bson.ObjectId(model.ObjectId));
                }

                if (result == null)
                    result = new Category();

                result.Name = model.Name;
                result.Active = model.Active;

                await _categoryService.SaveCategory(result);

                return RedirectToAction("CategorySetup");
            }
            return View();
        }