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));
        }
        public async Task <DALChangeDTO> FindDTOAsync(int changeId)
        {
            var change = await RepoDbSet
                         .Include(c => c.ChangeName)
                         .ThenInclude(name => name.Translations)
                         .Include(c => c.ChangeInCategories)
                         .ThenInclude(obj => obj.Category)
                         .Include(c => c.Prices)
                         .Where(c => c.IsDeleted == false && c.Id == changeId)
                         .SingleOrDefaultAsync();

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

            var currentPrice = PriceFinder.ForChange(change, change.Prices, DateTime.Now);

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

            return(ChangeMapper.FromDomain(change));
        }
Example #3
0
 /// <summary>
 /// Maps Id, Name, OrgId, Price
 /// </summary>
 /// <param name="change"></param>
 /// <param name="time"></param>
 /// <returns></returns>
 /// <exception cref="NullReferenceException"></exception>
 public static DALChangeDTO FromDomain2(Change change, DateTime time)
 {
     if (change == null)
     {
         throw new NullReferenceException("Can't map, change entity is null!");
     }
     return(new DALChangeDTO()
     {
         Name = change.ChangeName.Translate(),
         Id = change.Id,
         OrganizationId = change.OrganizationId,
         CurrentPrice = PriceFinder.ForChange(change, change.Prices, time) ?? decimal.MinusOne
     });
 }
Example #4
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 #5
0
    void Start()
    {
        priceFinder = GameObject.FindObjectOfType <PriceFinder>();
        //float price = (float)priceFinder.GetClosePrice(DateTime.Parse("2016-03-10"));

        // Uses a struct for Dictionary value so that multiple results per date can be returned
        // This is defined in the DictionaryHelper namespace
        closeDictionary closePriceRange = priceFinder.FindClosePricesByDates("2015-01-01", "2015-12-31");

        // Holder to see if today's close was greater or less than previous day to determine dot color
        double yesterdayClose = 0d;

        // Get max and min values to scale the y axis values
        float minClose    = (float)closePriceRange.Min(x => x.Value.closePrice);
        float maxClose    = (float)closePriceRange.Max(x => x.Value.closePrice);
        float spreadClose = maxClose - minClose;

        // Plot each scatter dot by date, time, volume and whether it was < or > day before
        foreach (KeyValuePair <DateTime, closeDetails> kvp in closePriceRange.OrderBy(k => k.Key))
        {
            // x position is chronological and y position is closing price; z is just placement
            float dayOfYear = kvp.Key.DayOfYear;
            float xPos      = dayOfYear / 365 * 20;
            float yPos      = ((float)kvp.Value.closePrice - minClose) / spreadClose * 2;
            float zPos      = 5f;

            // Width of the dot is volume
            float width = (float)kvp.Value.volume / 10000000000;

            // If closing price > yesterday's, green dot, otherwise it was a down day
            GameObject whichDot = kvp.Value.closePrice >= yesterdayClose ? plusHolder : negHolder;
            GameObject dot      = Instantiate(whichDot, new Vector3(xPos, yPos, zPos), Quaternion.identity) as GameObject;

            // Set width based on volume
            dot.transform.GetChild(0).transform.localScale += new Vector3(0, 0, width);

            // Keeping everything tidy
            dot.transform.parent = transform;

            // Generate the labels
            dot.GetComponentInChildren <TextMesh>().text = kvp.Key.ToString("d") + " " + kvp.Value.closePrice.ToString("F");

            yesterdayClose = kvp.Value.closePrice;
        }
    }
Example #6
0
        /// <summary>
        /// Maps Id, Name, Price, OrgId, CategoriesMin
        /// </summary>
        /// <param name="change"></param>
        /// <returns></returns>
        /// <exception cref="NullReferenceException"></exception>
        public static DALChangeDTO FromDomain(Change change)
        {
            if (change == null)
            {
                throw new NullReferenceException("Can't map, Domain.Change is null");
            }

            return(new DALChangeDTO()
            {
                Id = change.Id,
                Name = change.ChangeName?.Translate() ?? "CHANGE NAME NOT LOADED",
                CurrentPrice = PriceFinder.ForChange(change, change.Prices, DateTime.Now) ?? -1.0m,
                OrganizationId = change.OrganizationId,
                Categories = change.ChangeInCategories?
                             .Where(obj => obj.Category.IsDeleted == false)
                             .Select(obj => CategoryMapper.FromDomainToMin(obj.Category))
                             .ToList()
            });
        }
Example #7
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
            });
        }