public TariffGroupAggregate Get(long id)
        {
            var item = context.TariffGroupDTOs
                       .Join(context.LinkObjectsDTOs, t => t.Id, l => l.Childen.Id, (t, l) => new { trgroup = t, link = l })
                       .Where(l => !l.link.IsTransit)
                       .FirstOrDefault(v => v.trgroup.Id == id);

            if (item == null)
            {
                throw new ArgumentException($"Tariff Group id = {id} not found");
            }

            var result = new TariffGroupAggregate(item.link.Owner.Id, item.trgroup.Id, item.trgroup.Name, item.trgroup.Tariff.Name, item.trgroup.Tariff.Price,
                                                  item.link.BeginDate, item.link.EndDate, item.link.IsTransit, item.trgroup.Deleted && item.link.Deleded);

            return(result);
        }
 public void Update(TariffGroupAggregate item)
 {
     context.ExecuteInTransaction(() =>
     {
         var existed = context.TariffGroupDTOs.SingleOrDefault(x => x.Id == item.Id);
         if (existed != null)
         {
             Mapper.Map(item, existed);
             var link = context.LinkObjectsDTOs.Single(l => l.Owner.Id == item.OwnerId && l.Childen.Id == item.Id);
             Mapper.Map(item, link);
         }
         else
         {
             Create(item, true);
         }
     });
 }
 private void Create(TariffGroupAggregate item, bool notCheck)
 {
     context.ExecuteInTransaction(() =>
     {
         if (!notCheck && (item.Id != -1 || context.TariffGroupDTOs.SingleOrDefault(x => x.Id == item.Id) != null))
         {
             throw new ArgumentException($"Tariff Group id = {item.Id} found");
         }
         var newItem = Mapper.Map <TariffGroupDTO>(item);
         context.TariffGroupDTOs.Add(newItem);
         var link = new LinkObjectsDTO()
         {
             Owner     = context.ObjectDTOs.Single(o => o.Id == item.OwnerId),
             Childen   = newItem,
             BeginDate = item.BeginDate,
             EndDate   = item.EndDate,
             IsTransit = false,
         };
         context.LinkObjectsDTOs.Add(link);
         return(newItem);
     });
 }
 public void Create(TariffGroupAggregate item)
 {
     Create(item, false);
 }
Beispiel #5
0
 public IEnumerable <ChannelAggregate> GetByTariffGroup(TariffGroupAggregate tariffGroup)
 {
     return(GetByTariffGroup(tariffGroup.Id));
 }
Beispiel #6
0
 public IEnumerable <ConstantFlowAggregate> GetByTariffGroup(TariffGroupAggregate tariffGroup)
 {
     return(GetByTariffGroup(tariffGroup.Id));
 }