asp.net – AspnetCore – Empty -Structure

                Blog Controller
            
             1. I've the following code on my BlogControler.Cs (aspnet core 2.1):
            

                
                namespace FiorelloTask.Areas.AdminF.Controllers
                {
                
                    [Area("AdminF")]
                    public class BlogController : Controller
                    {
                        private AppDbContext _context;
                        private IWebHostEnvironment _env;
                        public BlogController(AppDbContext context, IWebHostEnvironment env)
                        {
                            _context = context;
                            _env = env;
                        }
                        public IActionResult Index()
                        {
                            List<Blog> blogs = _context.Blogs.ToList();
                            return View(blogs);
                        }
                       
                        public IActionResult Create()
                        {
                            return View();
                        }
                        [HttpPost]
                        [ValidateAntiForgeryToken] 
                        public async Task<IActionResult> Create(Blog blog)
                        {
                            //validationstate-requiredolanlar
                            if (ModelState["Photo"].ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
                            {
                                return View();
                
                            }
                
                            if (!blog.Photo.IsImage())
                            {
                                ModelState.AddModelError("Photo", "Accept only image!");
                
                                return View();
                            }
                            if (blog.Photo.ImageSize(10000))
                            {
                                ModelState.AddModelError("Photo", "1mq yuxari olabilmez!");
                
                                return View();
                            }
                
                            if (!ModelState.IsValid)
                            {
                                return View();
                            }
                            bool isExistName = _context.Blogs.Any(c => c.Title.ToLower() == blog.Title.ToLower());
                            if (isExistName)
                            {
                                ModelState.AddModelError("Name", "Eyni adlı kategoriya mövcuddur.");
                                return View();
                            }
                            //string path = @"C:UsersTOSHIBADesktopFiorelloAdminFFiorelloTaskwwwrootimg";
                
                            string fileName = await blog.Photo.SaveImage(_env, "img");
                            Blog newBlog = new Blog();
                            newBlog.Desc=blog.Desc;
                            newBlog.Title=blog.Title;
                            newBlog.Image = fileName;
                            await _context.Blogs.AddAsync(newBlog);
                            await _context.SaveChangesAsync();
                
                            return RedirectToAction("Index");
                        }
                        public async Task<IActionResult> Delete(int? id)
                        {
                            if (id == null) return NotFound();
                            Blog dbBlog = await _context.Blogs.FindAsync(id);
                            if (dbBlog == null) return NotFound();
                            _context.Blogs.Remove(dbBlog);
                            await _context.SaveChangesAsync();
                            return RedirectToAction(nameof(Index));
                        }
                
                    }
                }
            

I’m having some issues trying to configure batching for OData on an AspNETCore Web Application. I’ve searched everywhere (almost) and couldn’t find a proper answer. I’m not sure that the current AspNetCore.Odata version 7.0.0 which is still beta has support for batching. > CatagoryController

             2.CatagoryController
             
     
            
            namespace FiorelloTask.Areas.AdminF.Controllers
            {
                [Area("AdminF")]
                public class CategoryController : Controller
                {
                   
                    private AppDbContext _context;
                    public CategoryController(AppDbContext context)
                    {
                        _context = context;
            
                    }
            
            
                    public IActionResult Index()
                    {
                        List<Category> categories = _context.Categories.ToList();
                        return View(categories);
                    }
                    public async Task <IActionResult> Detail(int?id)
                    {
                        if (id == null) return NotFound();
                        Category dbCategory = await _context.Categories.FindAsync(id);
                        if (dbCategory == null) return NotFound();
                        return View(dbCategory);
                    }
                   
                    public async Task<IActionResult> Delete(int? id)
                    {
                        if (id == null) return NotFound();
                        Category dbCategory = await _context.Categories.FindAsync(id);
                        if (dbCategory == null) return NotFound();
                        _context.Categories.Remove(dbCategory);
                        await _context.SaveChangesAsync();
                        return RedirectToAction(nameof(Index));
                    }
                    public  IActionResult Create()
                    {
                        return View();
                    }
                    [HttpPost]
                    public async Task<IActionResult> Create(Category category)
                    {
                        if (!ModelState.IsValid)
                        {
                            return View();
                        }
                       bool isExistName= _context.Categories.Any(c => c.Name.ToLower() == category.Name.ToLower());
                        if (isExistName)
                        {
                            ModelState.AddModelError("Name", "Eyni adlı kategoriya mövcuddur.");
                            return View();
                        }
                        Category newCategory = new Category();
                        newCategory.Name = category.Name;
                        newCategory.Desc = category.Desc;
                       await  _context.Categories.AddAsync(newCategory);
                       await  _context.SaveChangesAsync();
                        return RedirectToAction(nameof(Index));
                    }
                    public async Task<IActionResult> Update(int? id)
                    {
                        if (id == null) return NotFound();
                        
                            Category dbCategory = await _context.Categories.FindAsync(id);
                            if (dbCategory == null) return NotFound();
            
                            return View(dbCategory);
                       
            
            
                    }
                    [HttpPost]
                    public async Task<IActionResult> Update(int?id,Category category)
                    {
                        if (!ModelState.IsValid)
                        {
                            return View();
                        }
                        Category dbCategory = await _context.Categories.FindAsync(id);
                        Category existNameCategory= _context.Categories
                            .FirstOrDefault(c=>c.Name.ToLower()==category.Name.ToLower());
            
                        if (existNameCategory!=null)
                        {
                            if (dbCategory!=existNameCategory)
                            {
                                ModelState.AddModelError("Name", "Name already exist");
                                return View();
                            }
                        }
                        if (dbCategory == null) return NotFound();
                        dbCategory.Name = category.Name;
                        dbCategory.Desc = category.Desc;
                        await _context.SaveChangesAsync();
                        return RedirectToAction(nameof(Index));
                    } 
            
                }
            }
        

I’m having some issues trying to configure batching for OData on an AspNETCore Web Application. I’ve searched everywhere (almost) and couldn’t find a proper answer. I’m not sure that the current AspNetCore.Odata version 7.0.0 which is still beta has support for batching. > DashBoard

         3. I've the following code on my DashBoard.Cs (aspnet core 2.1):
        
        using Microsoft.AspNetCore.Authorization;
        using Microsoft.AspNetCore.Mvc;
        
        namespace FiorelloTask.Areas.AdminF.Controllers
        {
            public class DashboardController : Controller
            {
                [Area("AdminF")]
                [Authorize(Roles ="Admin")]  
                public IActionResult Index()
                {
                    return View();
                }
            }
        }
        
         5. To create tokens when the user sign in, I've ProductContoroller service:
 
        
        namespace FiorelloTask.Areas.AdminF.Controllers
        {
            [Area("AdminF")]
            
            public class ProductController : Controller
            {
            private AppDbContext _context;
                    public ProductController(AppDbContext context)
                    {
                        _context = context;
        
                    }
                    public IActionResult Index(int take=5,int pageSize=1)
                {
                    List<Product> products = _context.Products
                        .Include(p => p.Category)
                        .Skip((pageSize-1)*take)
                        .Take(take)
                        .ToList();
        
                    Pagination<ProductVM> pagination = new Pagination<ProductVM>
                    (
                           ReturnPageCount(take),
                            pageSize,
                        MapProductToProductVM(products)
                     
                        
                    );
                    return View(pagination);
                }
                private List<ProductVM> MapProductToProductVM(List<Product> products)
                {
                    //List<ProductVM> productVMs = new List<ProductVM>();
        
                    //foreach (var item in products)
                    //{
                    //    ProductVM product = new ProductVM
                    //    {   
                    //        Id=item.Id,
                    //        Name = item.Name,
                    //        ImageUrl=item.ImageUrl,
                    //        Count=item.Count,
                    //        Price=item.Price,
                    //        CategoryName=item.Category.Name
        
        
                    //    };
                    //    productVMs.Add(product);
                    //}return productVMs;
        
                    List<ProductVM> productVMs = products.Select(p => new ProductVM
                    {
                        Id=p.Id,
                        Name=p.Name,
                        ImageUrl=p.ImageUrl,
                        Count=p.Count,
                        Price=p.Price,
                        CategoryName=p.Category.Name
                    }).ToList();
                    return productVMs;
                }
        
                private int ReturnPageCount(int take)
                {
                 int productCount = _context.Products.Count();
        
                    return (int)Math.Ceiling(((decimal)productCount/take));
                }
            }
        }
    
    My first perception on this, was that none of the startup authorization/authentication methods checked for the token, or at least I'm not providing it besides the TokenValidationParameters.
    
    I assumed that it worked because of the Token composition and the service would decompose it to extract the current user and insert it into Identity.
   

I’m having some issues trying to configure batching for OData on an AspNETCore Web Application. I’ve searched everywhere (almost) and couldn’t find a proper answer. I’m not sure that the current AspNetCore.Odata version 7.0.0 which is still beta has support for batching.

     - SliderController.Cs
    I assumed that it worked because of the Token composition and the service would decompose it to extract the current user and insert it into Identity.
    
    namespace FiorelloTask.Areas.AdminF.Controllers
    {
        [Area("AdminF")]
        public class SliderController : Controller
        {
            private AppDbContext _context;
            private IWebHostEnvironment _env;
            public SliderController(AppDbContext context,IWebHostEnvironment env)
            {
                _context = context;
                _env=env;
            }
    
            public IActionResult Index()
            {
                List<Slider> sliders = _context.Sliders.ToList();
                return View(sliders);
            }
            
            public IActionResult Create()
            {
                return View();
            }
            [HttpPost]
            [ValidateAntiForgeryToken] //jsda yazsaqbunusilmeliyik,yoxsaislemiir
            public async Task<IActionResult>Create(Slider slider)
            {
                //validationstate-requiredolanlar
                if (ModelState["Photo"].ValidationState==Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
                {
                    return View();
    
                }
    
                if (!slider.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Accept only image!");
    
                    return View();
                }
                if (slider.Photo.ImageSize(10000))
                {
                    ModelState.AddModelError("Photo", "1mq yuxari olabilmez!");
    
                    return View();
                }
                //string path = @"C:UsersTOSHIBADesktopFiorelloAdminFFiorelloTaskwwwrootimg";
    
                string fileName = await slider.Photo.SaveImage(_env,"img");
                Slider newSlider = new Slider();
                newSlider.ImageUrl = fileName;
                await _context.Sliders.AddAsync(newSlider);
                await _context.SaveChangesAsync();
    
                return RedirectToAction("Index");
            }
    
            public async Task<IActionResult> Delete(int?id)
            {
                if (id == null) return NotFound();
                Slider dbSlider =await _context.Sliders.FindAsync(id);
                if (dbSlider == null) return NotFound();
                Helper.DeleteFile(_env, "img",dbSlider.ImageUrl);
                _context.Sliders.Remove(dbSlider);
                await _context.SaveChangesAsync();
                return RedirectToAction("Index");
    
    
            }
        }
    }

Leave a Comment