public IActionResult Save([FromBody] Data.DTO.Category_Save_Request dto) { if (ModelState.IsValid) { return(BadRequest("kötü çocuk")); } Data.Entities.Category category = null; Data.Entities.Menu menu = null; Data.Entities.Category parentCategory = null; if (dto.MenuId != null) { menu = _unitOfWork.MenuRepository.Get((int)dto.MenuId); } if (dto.ParentCategoryId != null) { parentCategory = _unitOfWork.CategoryRepository.Get((int)dto.ParentCategoryId); } if (dto.CategoryId == 0) { //yeni kayıt category = new Data.Entities.Category() { Active = true, CreateDate = DateTime.UtcNow, Menu = menu, Name = dto.Name, Parent = parentCategory }; _unitOfWork.CategoryRepository.Insert(category); _unitOfWork.Complete(); } else { //güncelleme category = _unitOfWork.CategoryRepository .Query() .Include(a => a.Parent) .Include(a => a.Menu) .SingleOrDefault(a => a.Id == dto.CategoryId); if (category == null) { return(BadRequest("kaydetmeye çalıştığınız kategori bulunamadı")); } category.Name = dto.Name; category.Menu = menu; category.Parent = parentCategory; _unitOfWork.CategoryRepository.Insert(category); _unitOfWork.Complete(); } return(new JsonResult(category)); }
public async Task <CategoryDTO> GetByIdAsync(Guid id) { Data.Entities.Category category = await _context.FindAsync <Data.Entities.Category>(id); if (category is null || category.DeletedDate != null) { return(new CategoryDTO()); } return(CloneCategoryEntity(category)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Category = await _context.Categories.FirstOrDefaultAsync(m => m.Id == id); if (Category == null) { return(NotFound()); } return(Page()); }
public CategoryDTO CloneCategoryEntity(Data.Entities.Category category) { CategoryDTO categoryDTO = new CategoryDTO { Id = category.Id, Name = category.Name, Description = category.Description, CreatedDate = category.CreatedDate, CreatedBy = category.CreatedBy, UpdatedDate = category.UpdatedDate, UpdatedBy = category.UpdatedBy, DeletedDate = category.DeletedDate, DeletedBy = category.DeletedBy, }; return(categoryDTO); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Category = await _context.Categories.FindAsync(id); if (Category != null) { _context.Categories.Remove(Category); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public Category(Data.Entities.Category _category) { this.Id = _category.Id; this.Name = _category.Name?.GetLocalizationValue(); this.Position = _category.Position; }