private BasketItemEntity GetBasketEntity(CatalogItemEntity entity) { LoadBasket(entity); BasketItemEntity basketItem = entity.BasketItems.FirstOrDefault(x => x.Order == null); return(basketItem); }
public static CatalogItemEntity Assemble(CatalogInfo catalogInfo, BrandItemEntity brandItem, List <PhotoItemEntity> photos, DirectoryEntity directory) { CatalogItemEntity catalogItem = new CatalogItemEntity { Id = catalogInfo.Id, UID = catalogInfo.UID, Code = catalogInfo.Code, Article = catalogInfo.Article, Brand = brandItem, BrandName = brandItem?.Name, Name = catalogInfo.Name, Unit = catalogInfo.Unit, EnterpriceNormPack = catalogInfo.EnterpriceNormPack, BatchOfSales = catalogInfo.BatchOfSales, Balance = catalogInfo.Balance, Price = catalogInfo.Price, Currency = catalogInfo.Currency, Multiplicity = catalogInfo.Multiplicity, HasPhotos = catalogInfo.HasPhotos, Photos = photos, DateOfCreation = catalogInfo.DateOfCreation, LastUpdated = catalogInfo.LastUpdated, ForceUpdated = catalogInfo.ForceUpdated, Status = Convert(catalogInfo.Status), LastUpdatedStatus = catalogInfo.LastUpdatedStatus, Directory = directory }; return(catalogItem); }
private void Update(CatalogItemEntity entity, CatalogInfo catalogInfo) { BrandItemEntity brandItem = GetBrandWithLoad(catalogInfo.BrandId); DirectoryEntity directory = GetDirectoryWithLoad(catalogInfo.DirectoryId); List <PhotoItemEntity> photos = GetPhotosWithLoad(catalogInfo.Photos); entity.Id = catalogInfo.Id; entity.UID = catalogInfo.UID; entity.Code = catalogInfo.Code; entity.Article = catalogInfo.Article; entity.Brand = brandItem; entity.BrandName = brandItem?.Name; entity.Name = catalogInfo.Name; entity.Unit = catalogInfo.Unit; entity.EnterpriceNormPack = catalogInfo.EnterpriceNormPack; entity.BatchOfSales = catalogInfo.BatchOfSales; entity.Balance = catalogInfo.Balance; entity.Price = catalogInfo.Price; entity.Currency = catalogInfo.Currency; entity.Multiplicity = catalogInfo.Multiplicity; entity.HasPhotos = catalogInfo.HasPhotos; entity.Photos = photos; entity.DateOfCreation = catalogInfo.DateOfCreation; entity.LastUpdated = catalogInfo.LastUpdated; entity.ForceUpdated = catalogInfo.ForceUpdated; entity.Status = LoadAssembler.Convert(catalogInfo.Status); entity.LastUpdatedStatus = catalogInfo.LastUpdatedStatus; entity.Directory = directory; }
public void LoadPhotos(CatalogItemEntity entity) { if (!DataBaseContext.Entry(entity).Collection(c => c.Photos).IsLoaded) { DataBaseContext.Entry(entity).Collection(c => c.Photos).Load(); } }
public void LoadBasket(CatalogItemEntity entity) { if (!DataBaseContext.Entry(entity).Collection(c => c.BasketItems).IsLoaded) { DataBaseContext.Entry(entity).Collection(c => c.BasketItems).Load(); } }
public PriceInfo GetPrice(CatalogItemEntity catalogItem, string login) { ContragentItemEntity contragentItem = GetContagent(login); PriceInfo result = GetPrice(catalogItem, contragentItem); return(result); }
private CatalogItemEntity Create(CatalogInfo catalogInfo) { BrandItemEntity brandItem = GetBrandWithLoad(catalogInfo.BrandId); DirectoryEntity directory = GetDirectoryWithLoad(catalogInfo.DirectoryId); List <PhotoItemEntity> photos = GetPhotosWithLoad(catalogInfo.Photos); CatalogItemEntity entity = LoadAssembler.Assemble(catalogInfo, brandItem, photos, directory); return(entity); }
public CatalogItem(CatalogItemEntity entity, IDataService databaseService, IImageService imageService) { Entity = entity; this.databaseService = databaseService; this.imageService = imageService; Position = 1L; Refresh(); }
private CatalogItem BuildItem(CatalogItemEntity entity) { return(new CatalogItem { Id = entity.Id, Name = entity.Name, Description = entity.Description, Price = entity.Price, AvailableStock = entity.AvailableStock }); }
public void AddPhoto(CatalogItemEntity entity, byte[] photo) { PhotoItemEntity photoEntity = new PhotoItemEntity { Photo = photo }; DataBaseContext.PhotoItemEntities.Add(photoEntity); entity.Photos.Add(photoEntity); DataBaseContext.SaveChanges(); }
private PriceInfo GetPrice(CatalogItemEntity catalogItem, ContragentItemEntity contragentItem) { var result = new PriceInfo(); if (catalogItem != null && contragentItem != null) { TypeOfPriceItemEntity typeOfPrice = GetTypeOfPrice(catalogItem, contragentItem); result = GetPrice(catalogItem, typeOfPrice); decimal rate = GetRate(catalogItem, contragentItem); result.Price += result.Price + rate / 100; } return(result); }
public async Task <long> AddItem(CatalogItem model) { var item = new CatalogItemEntity { Name = model.Name, Description = model.Description, Price = model.Price }; _catalogContext.CatalogItems.Add(item); await _catalogContext.SaveChangesAsync(); return(item.Id); }
private PriceTypePriceGroupContragentEntity GetPriceTypePriceGroup( CatalogItemEntity catalogItem, ContragentItemEntity contragentItem) { PriceTypePriceGroupContragentEntity priceTypePriceGroup = null; PriceGroupItemEntity priceGroup = catalogItem.PriceGroup; if (priceGroup != null && contragentItem.PriceTypePriceGroups != null) { priceTypePriceGroup = contragentItem .PriceTypePriceGroups.FirstOrDefault(x => x.PriceGroupItem.Id == priceGroup.Id); } return(priceTypePriceGroup); }
private PriceTypeNomenclatureGroupContragentEntity GetPriceTypeNomenclatureGroup( CatalogItemEntity catalogItem, ContragentItemEntity contragentItem) { PriceTypeNomenclatureGroupContragentEntity priceTypeNomenclatureGroupContragent = null; NomenclatureGroupEntity nomenclatureGroup = catalogItem.NomenclatureGroup; if (nomenclatureGroup != null && contragentItem.PriceTypeNomenclatureGroups != null) { priceTypeNomenclatureGroupContragent = contragentItem .PriceTypeNomenclatureGroups.FirstOrDefault( x => x.NomenclatureGroupItem.Id == nomenclatureGroup.Id); } return(priceTypeNomenclatureGroupContragent); }
private decimal GetRate(CatalogItemEntity catalogItem, ContragentItemEntity contragentItem) { decimal rate = 0; if (contragentItem.Discounts != null) { DiscountsContragentEntity discount = contragentItem.Discounts.FirstOrDefault(x => x.CatalogItem.Id == catalogItem.Id); if (discount != null) { rate = discount.Rate; } } return(rate); }
private PriceInfo GetPrice(CatalogItemEntity catalogItem, TypeOfPriceItemEntity typeOfPrice) { var result = new PriceInfo(); if (typeOfPrice != null) { TypeOfPricesNomenclatureItemEntity typeOfPricesNomenclature = catalogItem.TypeOfPriceItems.FirstOrDefault(x => x.Id == typeOfPrice.Id); if (typeOfPricesNomenclature != null) { result.Price = typeOfPricesNomenclature.Price; result.Currency = typeOfPricesNomenclature.Currency; } } return(result); }
public void DownLoadCatalogItem(CatalogInfo catalogInfo) { CatalogItemEntity oldEntity = GetCatalogItem(catalogInfo.Id); if (oldEntity != null) { Update(oldEntity, catalogInfo); dataService.DataBaseContext.SaveChanges(); webService.ConfirmUpdateCatalogs(new[] { oldEntity.Id }); } else { CatalogItemEntity entity = Create(catalogInfo); dataService.Insert(entity); entity = dataService.DataBaseContext.CatalogItemEntities.Find(catalogInfo.Id); if (entity != null) { webService.ConfirmUpdateCatalogs(new[] { catalogInfo.Id }); } } }
private CatalogInfo Assemble(CatalogItemEntity item, string login) { CatalogInfo result = null; if (item != null) { PriceInfo priceInfo = priceService.GetPrice(item, login); result = new CatalogInfo { Id = item.Id, UID = item.UID, Code = item.Code, Article = item.Article, Name = item.Name, BrandId = item.Brand?.Id, BrandName = item.BrandName, Unit = item.Unit, EnterpriceNormPack = item.EnterpriceNormPack, BatchOfSales = item.BatchOfSales, Balance = item.Balance, Price = priceInfo.Price, Currency = priceInfo.Currency, Multiplicity = item.Multiplicity, HasPhotos = item.HasPhotos, Photos = item.Photos?.Select(x => x.Id).ToList() ?? new List <long>(), DateOfCreation = item.DateOfCreation, LastUpdated = item.LastUpdated, ForceUpdated = item.ForceUpdated, Status = item.Status, LastUpdatedStatus = item.LastUpdatedStatus, DirectoryId = item.Directory?.Id }; } return(result); }
private TypeOfPriceItemEntity GetTypeOfPrice(CatalogItemEntity catalogItem, ContragentItemEntity contragentItem) { TypeOfPriceItemEntity typeOfPrice = null; PriceTypeNomenclatureGroupContragentEntity priceTypeNomenclatureGroupContragent = GetPriceTypeNomenclatureGroup(catalogItem, contragentItem); if (priceTypeNomenclatureGroupContragent != null) { typeOfPrice = priceTypeNomenclatureGroupContragent.TypeOfPriceItem; } else { PriceTypePriceGroupContragentEntity priceTypePriceGroup = GetPriceTypePriceGroup(catalogItem, contragentItem); if (priceTypePriceGroup != null) { typeOfPrice = priceTypePriceGroup.TypeOfPriceItem; } } return(typeOfPrice); }
public void SetCount(CatalogItemEntity entity, decimal count) { BasketItemEntity basketItem = GetBasketEntity(entity); if (count == 0) { if (basketItem != null) { Delete(basketItem); } } else { if (basketItem == null) { basketItem = new BasketItemEntity(); entity.BasketItems.Add(basketItem); } basketItem.Count = count; basketItem.DateAction = DateTimeOffset.Now; DataBaseContext.SaveChanges(); } }
public decimal GetCount(CatalogItemEntity entity) { decimal count = entity != null?GetBasketEntity(entity)?.Count ?? 0 : 0; return(count); }
private CatalogItemEntity GetCatalogItem(long id) { CatalogItemEntity entity = catalogRepository.GetItem(id); return(entity); }