public List <ShoesViewModel> GetAll() { List <Shoes> lsShoes = _shoesRepository .GetAll() .Where(s => s.IsAvaiable == true) .Include(s => s.ShoesHasSize) .Include(a => a.Brand) .ToList(); List <ShoesViewModel> lsShoesVM = new List <ShoesViewModel>(); ShoesViewModel shoesVM = null; ShoesHasSizeViewModel shoesHasSizeVM = null; foreach (var shoes in lsShoes) { shoesVM = new ShoesViewModel() { Id = shoes.Id, BrandId = shoes.BrandId, BrandName = shoes.Brand.Name, Color = shoes.Color, IsAvaiable = shoes.IsAvaiable, Name = shoes.Name, Description = shoes.Description, Price = shoes.Price, Sex = shoes.Sex }; foreach (var shs in shoes.ShoesHasSize) { ShoesHasSize shoesHasSize = _shoesHasSizeRepository.GetAll() .Where(h => h.Id == shs.Id).Include(h => h.Size).FirstOrDefault(); shoesHasSizeVM = new ShoesHasSizeViewModel() { Id = shoesHasSize.Id, Quantity = shoesHasSize.Quantity, Scale = shoesHasSize.Size.Scale, ShoesId = shoesHasSize.ShoesId, SizeId = shoesHasSize.SizeId }; shoesVM.ShoesHasSizes.Add(shoesHasSizeVM); } List <Image> images = _imageRepository.GetAll().Where(i => i.IsShoes == true && i.OwnId == shoes.Id).ToList(); shoesVM.Images = images; lsShoesVM.Add(shoesVM); } return(lsShoesVM); }
public IActionResult GetShoesHasSize(int id) { ShoesHasSizeViewModel shoesHasSizeVM = _shoesHasSizeService.GetShoesHasSize(id); if (shoesHasSizeVM != null) { return(new JsonResult(shoesHasSizeVM) { StatusCode = StatusCodes.Status200OK }); } return(new JsonResult(null) { StatusCode = StatusCodes.Status409Conflict }); }
public ShoesHasSizeViewModel GetShoesHasSize(int id) { ShoesHasSize shs = _shoesHasSizeRepository.GetAll().Where(s => s.Id == id).Include(s => s.Shoes).Include(s => s.Size).FirstOrDefault(); if (shs != null) { ShoesHasSizeViewModel shoesHasSizeVM = new ShoesHasSizeViewModel() { Id = shs.Id, Quantity = shs.Quantity, Scale = shs.Size.Scale, ShoesId = shs.ShoesId, ShoesName = shs.Shoes.Name, SizeId = shs.SizeId }; return(shoesHasSizeVM); } return(null); }
public List <ShoesHasSizeViewModel> GetShoesHasSizes() { List <ShoesHasSize> shoesHasSizes = _shoesHasSizeRepository.GetAll().Include(s => s.Shoes).Include(s => s.Size).ToList(); List <ShoesHasSizeViewModel> shoesHasSizeVMs = new List <ShoesHasSizeViewModel>(); ShoesHasSizeViewModel shoesHasSizeVM = null; foreach (var shs in shoesHasSizes) { shoesHasSizeVM = new ShoesHasSizeViewModel() { Id = shs.Id, Quantity = shs.Quantity, Scale = shs.Size.Scale, ShoesId = shs.ShoesId, ShoesName = shs.Shoes.Name, SizeId = shs.SizeId }; shoesHasSizeVMs.Add(shoesHasSizeVM); } return(shoesHasSizeVMs); }