Ejemplo n.º 1
0
        public TransactionDetails Create(TransactionDetails transaction)
        {
            var entity = new Entities.Transaction();

            if (transaction.Partner != null)
            {
                entity.Partner = Partners
                                 .Single(x => x.Id == transaction.Partner.Id);
            }

            if (transaction.Condominium != null)
            {
                entity.Condominium = Condominiums
                                     .Single(x => x.Id == transaction.Condominium.Id);
            }
            entity.Tags = transaction.Tags
                          .Select(x => new TransactionTag()
            {
                Label = x.Label, Ratio = x.Rate
            })
                          .ToList();
            DbContext.AddRange(entity.Tags);
            DbContext.Add(transaction);
            DbContext.SaveChanges();

            return(entity.ToModelDetails());
        }
Ejemplo n.º 2
0
        public BillDetails CreateBill(BillDetails bill)
        {
            var entity = new Entities.Bill()
            {
                Created = bill.Created,
                Partner = bill.Partner != null?Partners
                          .Single(x => x.Id == bill.Partner.Id) : null,
                              Condominium = bill.Condominium != null?Condominiums
                                            .Single(x => x.Id == bill.Condominium.Id) : null,
                                                Description     = bill.Description,
                                                Serial          = bill.Serial,
                                                PaymentDeadline = bill.PaymentDeadline,
                                                Done            = bill.Done,
                                                Items           = bill.Items
                                                                  .Select(x => new Entities.BillItem()
                {
                    Description = x.Description, Price = x.Price
                })
                                                                  .ToList(),
                                                Tags = bill.Tags
                                                       .Select(x => new BillTag()
                {
                    Label = x.Label, Ratio = x.Rate
                })
                                                       .ToList()
            };

            DbContext.Add(entity);
            DbContext.Add(entity.Tags);
            DbContext.Add(entity.Items);
            DbContext.SaveChanges();

            return(entity.ToModelWithItems());
        }
Ejemplo n.º 3
0
        public BillDetails Edit(BillDetails bill)
        {
            var entity = Bills.First(x => x.Id == bill.Id);

            entity.Created = bill.Created ?? DateTime.Now;
            entity.Partner = bill.Partner is null ?  null:
                             Partners.Single(x => x.Id == bill.Partner.Id);
            entity.Condominium = bill.Condominium is null ? null:
                                 Condominiums.Single(x => x.Id == bill.Condominium.Id);
            entity.Description     = bill.Description;
            entity.Serial          = bill.Serial;
            entity.PaymentDeadline = bill.PaymentDeadline;
            entity.Done            = bill.Done;

            DbContext.RemoveRange(BillItems.Where(x => x.Bill == entity));
            entity.Items = bill.Items
                           .Select(x => new Entities.BillItem()
            {
                Description = x.Description, Price = x.Price
            })
                           .ToList();
            DbContext.AddRange(entity.Items);

            DbContext.RemoveRange(DbContext.BillTags.Where(x => x.Bill == entity));
            entity.Tags = bill.Tags
                          .Select(x => new BillTag()
            {
                Label = x.Label, Ratio = x.Rate
            })
                          .ToList();
            DbContext.AddRange(entity.Tags);

            DbContext.SaveChanges();

            return(entity.ToModelWithItems());
        }
Ejemplo n.º 4
0
 public Condominium Get(int id) =>
 Condominiums.Single(x => x.Id == id).ToModel();