示例#1
0
        public async Task <IActionResult> Create([Bind("Id,Title,Content,CategoryId,Image,LastModificationTime")] PostModel postModel)
        {
            if (ModelState.IsValid)
            {
                var post = new Post
                {
                    Title        = postModel.Title,
                    Content      = postModel.Content,
                    Image        = postModel.Image,
                    CategoryId   = postModel.CategoryId,
                    CreationTime = DateTime.UtcNow
                };
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(postModel));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Image, CategoryType, LastModificationTime")] CategoryModel categoryModel)
        {
            if (ModelState.IsValid)
            {
                var category = new Category
                {
                    Name         = categoryModel.Name,
                    Description  = categoryModel.Description,
                    Image        = categoryModel.Image,
                    CreationTime = DateTime.UtcNow,
                    CategoryType = categoryModel.CategoryType
                };

                await _context.AddAsync(category);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoryModel));
        }