public async Task <DALProductDTO> FindDTOAsync(int productId)
        {
            var product = await RepoDbSet
                          .Include(p => p.ProductName)
                          .ThenInclude(p => p.Translations)
                          .Include(p => p.ProductDescription)
                          .ThenInclude(desc => desc.Translations)
                          .Include(p => p.ProductInCategories)
                          .ThenInclude(obj => obj.Category)
                          .ThenInclude(category => category.CategoryName)
                          .ThenInclude(name => name.Translations)
                          .Include(p => p.Prices)
                          .Where(p => p.IsDeleted == false && p.Id == productId)
                          .SingleOrDefaultAsync();

            if (product == null)
            {
                return(null);
            }

            var currentPrice = PriceFinder.ForProduct(product, product.Prices, DateTime.Now);

            if (currentPrice == null)
            {
                return(null);
            }

            return(ProductMapper.FromDomain(product));
        }
Example #2
0
        /// <summary>
        /// Maps id, name, desc, price(at given time), orgId
        /// </summary>
        /// <param name="product"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        /// <exception cref="NullReferenceException"></exception>
        public static DALProductDTO FromDomain2(Product product, DateTime time)
        {
            if (product == null)
            {
                throw new NullReferenceException("Can't use Mapper on a null object");
            }

            return(new DALProductDTO()
            {
                Id = product.Id,
                CurrentPrice = PriceFinder.ForProduct(product, product.Prices, time) ?? -1.0m,
                Name = product.ProductName?.Translate() ?? "PRODUCT NAME NOT LOADED",
                Description = product.ProductDescription?.Translate() ?? "PRODUCT DESCRIPTION NOT LOADED",
                OrganizationId = product.OrganizationId,
            });
        }
Example #3
0
        /// <summary>
        /// Maps id, price, name, desc, orgId, CategoriesMin
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public static DALProductDTO FromDomain(Product product)
        {
            if (product == null)
            {
                throw new NullReferenceException("Can't use Mapper on a null object");
            }

            return(new DALProductDTO()
            {
                Id = product.Id,
                CurrentPrice = PriceFinder.ForProduct(product, product.Prices, DateTime.Now) ?? -1.0m,
                Name = product.ProductName?.Translate() ?? "PRODUCT NAME NOT LOADED",
                Description = product.ProductDescription?.Translate() ?? "PRODUCT DESCRIPTION NOT LOADED",
                OrganizationId = product.OrganizationId,
                Categories = product.ProductInCategories != null && product.ProductInCategories.Any() ?
                             product.ProductInCategories
                             .Where(obj => !obj.Category.IsDeleted)
                             .Select(obj => CategoryMapper.FromDomainToMin(obj.Category))
                             .ToList():
                             null
            });
        }