public List <ClothDTO> GetInventory() { List <ClothDTO> retval = new List <ClothDTO>(); using (DB = new storesEntities()) { try { var list = DB.Clothes.Select(i => i).ToList <Cloth>(); if (list != null) { ClothDTO dto = new ClothDTO(); foreach (var item in list) { ClothDTO cloth = dto.ToDTO(item); cloth.CompanyName = GetCompanyNameById(cloth.CompanyId); retval.Add(cloth); } } } catch (Exception e) { throw; } return(retval); } }
public List <ClothDTO> GetInventoryById(int id) { InventoryService InventoryService = new InventoryService(); List <ClothDTO> retval = default; try { using (db = new storesEntities()) { var list = db.Inventories.Where(inv => inv.StoreID == id).Select(i => i.ClothID).ToList(); if (list != null) { retval = new List <ClothDTO>(); List <Cloth> listcloth = db.Clothes.Where(c => list.Contains(c.ClothID)).Select(cloth => cloth).ToList <Cloth>(); foreach (var item in listcloth) { ClothDTO c = new ClothDTO(); c = c.ToDTO(item); c.CompanyName = InventoryService.GetCompanyNameById(c.CompanyId); retval.Add(c); } } return(retval); } } catch (Exception e) { throw; } }
public async Task Add(ClothDTO dto) { Cloth entity = _mapper.Map <Cloth>(dto); ClothRepository.Insert(entity); await _unitOfWork.commitAsync(); }
public async Task <ActionResult <ClothDTO> > GetClothDTO(int id) { ClothDTO dto = await _service.Get(id); if (dto == null) { return(NotFound()); } return(dto); }
public OperationDetails UpdateCloth(ProductDTO product, ClothDTO item, string oldClothName) { if (product == null || item == null) { return(new OperationDetails(false, "ОбЪект ссылается на null", this.ToString())); } Product localProduct = UpdateProduct(product); Database.Products.Update(localProduct); Cloth oldCloth = Database.Clothes.Find(x => x.Name == oldClothName).FirstOrDefault(); if (oldCloth == null) { return(new OperationDetails(false, "Не удалось найти объект", this.ToString())); } List <Color> colors = new List <Color>(); foreach (var col in item.Colors) { Color color = Database.Colors.Find(c => c.Name == col.Name).FirstOrDefault(); if (color != null) { colors.Add(color); } } oldCloth.Colors = colors; List <StringData> sizes = new List <StringData>(); foreach (var siz in item.Sizes) { StringData size = Database.StringDatas.Find(c => c.Data == siz.Data).FirstOrDefault(); if (size == null) { sizes.Add(new StringData() { Data = siz.Data }); } else { sizes.Add(size); } } oldCloth.Sizes = sizes; oldCloth.Composition = item.Composition; oldCloth.Type = item.Type; oldCloth.ForMen = item.ForMen; oldCloth.Properties = _mappers.ToProperty.Map <IEnumerable <PropertyDTO>, ICollection <Property> >(item.Properties); Database.Clothes.Update(oldCloth); Database.Save(); return(new OperationDetails(true, "Вещь успешно изменeнa", this.ToString())); }
public ActionResult CreateCloth(CreateClothVM item) { if (ModelState.IsValid) { ProductDTO product = new ProductDTO() { Name = item.Name, Description = item.Description, Price = item.Price, Sale = item.Sale }; ClothDTO cloth = new ClothDTO(); if (item.Images != null) { foreach (var i in item.Images) { ImageDTO image = new ImageDTO(); image.Text = item.Alt; using (var reader = new BinaryReader(i.InputStream)) image.Photo = reader.ReadBytes(i.ContentLength); product.Images = new List <ImageDTO>(); product.Images.Add(image); } } else { foreach (var i in item.ImagesInDatebase) { product.Images = new List <ImageDTO>(); product.Images.Add(_mappers.ToImageDTO.Map <ImageDM, ImageDTO>(i)); } } cloth.Composition = item.Composition; if (item.ForMen == "Для мужчин") { cloth.ForMen = true; } else { cloth.ForMen = false; } cloth.Name = item.Name; cloth.Type = item.Type; cloth.Properties = _mappers.ToPropertyDTO.Map <ICollection <PropertyDM>, List <PropertyDTO> >(item.Properties); cloth.Colors = new List <ColorDTO>(); foreach (var i in item.SelectedColors) { cloth.Colors.Add(new ColorDTO() { Name = i }); } cloth.Sizes = new List <StringDataDTO>(); foreach (var i in item.Sizes) { cloth.Sizes.Add(new StringDataDTO() { Data = i }); } OperationDetails result = _adminService.CreateCloth(product, cloth, product.Name); ViewBag.Result = result.Message; ViewBag.Status = result.Succedeed; List <ColorDM> colors = _mappers.ToColorDM.Map <ICollection <ColorDTO>, List <ColorDM> >(_adminService.GetColors()); var colorItems = colors.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name }).ToList(); item.Colors = colorItems; return(View(item)); } return(View()); }
public Task Update(ClothDTO dto) { throw new System.NotImplementedException(); }
public OperationDetails CreateCloth(ProductDTO product, ClothDTO item, string oldCloth) { Product productInDB = Database.Products.Find(p => p.Name == oldCloth).FirstOrDefault(); if (productInDB != null) { return(UpdateCloth(product, item, oldCloth)); } if (item == null || product == null) { return(new OperationDetails(false, "ОбЪект ссылается на null", this.ToString())); } Cloth cloth = _mappers.ToCloth.Map <ClothDTO, Cloth>(item); List <Color> colors = new List <Color>(); foreach (var col in item.Colors) { Color color = Database.Colors.Find(c => c.Name == col.Name).FirstOrDefault(); if (color != null) { colors.Add(color); } } cloth.Colors = colors; List <StringData> sizes = new List <StringData>(); foreach (var siz in item.Sizes) { StringData size = Database.StringDatas.Find(c => c.Data == siz.Data).FirstOrDefault(); if (size == null) { sizes.Add(new StringData() { Data = siz.Data }); } else { sizes.Add(size); } } cloth.Sizes = sizes; cloth.Name = product.Name; Database.Clothes.Add(cloth); Database.Save(); Product localProduct = _mappers.ToProduct.Map <ProductDTO, Product>(product); if (localProduct == null) { return(new OperationDetails(false, "Не удалось преобразовать объект", this.ToString())); } localProduct = CreateProduct(localProduct); localProduct.Table = Goods.Cloth; cloth = Database.Clothes.Find(x => x.Name == localProduct.Name).FirstOrDefault(); if (cloth == null) { return(new OperationDetails(false, "Не удалось найти объект", this.ToString())); } localProduct.FromTableId = cloth.Id; Database.Products.Add(localProduct); Database.Save(); return(new OperationDetails(true, "Вещь была успешно добавлена", this.ToString())); }