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));
        }
Exemple #2
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
     });
 }
Exemple #3
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()
            });
        }