Ejemplo n.º 1
0
        private ContractRentableItemVersion MapVersion(ContractRentableItem contractRentableItem)
        {
            ContractRentableItemVersion contractRentableItemVersion = new ContractRentableItemVersion
            {
                ContractId             = contractRentableItem.ContractId,
                CreatedAt              = contractRentableItem.CreatedAt,
                CreatedByUserId        = contractRentableItem.CreatedByUserId,
                RentableItemId         = contractRentableItem.RentableItemId,
                UpdatedAt              = contractRentableItem.UpdatedAt,
                UpdatedByUserId        = contractRentableItem.UpdatedByUserId,
                Version                = contractRentableItem.Version,
                ContractRentableItemId = contractRentableItem.Id
            };

            return(contractRentableItemVersion);
        }
Ejemplo n.º 2
0
        public async Task Delete(eFormRentableItemPnDbContext dbContext)
        {
            ContractRentableItem contractRentableItem =
                await dbContext.ContractRentableItem.FirstOrDefaultAsync(x => x.Id == Id);

            if (contractRentableItem == null)
            {
                throw new NullReferenceException($"Could not find ContractRentableItem with Id:{Id}");
            }

            contractRentableItem.WorkflowState = Constants.WorkflowStates.Removed;

            if (dbContext.ChangeTracker.HasChanges())
            {
                contractRentableItem.UpdatedAt       = DateTime.Now;
                contractRentableItem.UpdatedByUserId = UpdatedByUserId;
                contractRentableItem.Version        += 1;

                await dbContext.ContractRentableItemVersion.AddAsync(MapVersion(contractRentableItem));

                await dbContext.SaveChangesAsync();
            }
        }