Exemple #1
0
        private void SetSubscription(IAirProToolDto tool, AirProToolEntityModel update)
        {
            if (tool.Subscriptions == null)
            {
                return;
            }

            var reqsToAdd = tool.Subscriptions
                            .Where(x => update.Subscriptions.All(y => y.ToolSubscriptionId != x.ToolSubscriptionId))
                            .ToList();

            var reqsToUpdate = tool.Subscriptions
                               .Where(x => update.Subscriptions.Any(y => y.ToolSubscriptionId == x.ToolSubscriptionId))
                               .ToList();

            var reqsToDelete = update.Subscriptions
                               .Where(
                x => tool.Subscriptions.All(y => y.ToolSubscriptionId != x.ToolSubscriptionId))
                               .ToList();

            foreach (var item in reqsToAdd)
            {
                update.Subscriptions.Add(new AirProToolSubscriptionEntityModel
                {
                    ToolId   = tool.ToolId.GetValueOrDefault(),
                    Vendor   = item.Vendor,
                    Username = item.Username,
                    Password = item.Password
                });
            }

            foreach (var item in reqsToUpdate)
            {
                var dbObj = update.Subscriptions.FirstOrDefault(d => d.ToolSubscriptionId == item.ToolSubscriptionId);
                if (dbObj == null)
                {
                    continue;
                }

                dbObj.Vendor   = item.Vendor;
                dbObj.Username = item.Username;
                dbObj.Password = item.Password;
            }

            foreach (var item in reqsToDelete)
            {
                update.Subscriptions.Remove(item);
            }
        }
Exemple #2
0
        private void SetDeposits(IAirProToolDto tool, AirProToolEntityModel update)
        {
            if (tool.Subscriptions == null)
            {
                return;
            }

            var reqsToAdd = tool.Deposits
                            .Where(x => update.Deposits.All(y => y.ToolDepositId != x.ToolDepositId))
                            .ToList();

            var reqsToUpdate = tool.Deposits
                               .Where(x => update.Deposits.Any(y => y.ToolDepositId == x.ToolDepositId))
                               .ToList();

            foreach (var item in reqsToAdd)
            {
                update.Deposits.Add(new AirProToolDepositEntityModel
                {
                    ToolId      = tool.ToolId.GetValueOrDefault(),
                    Date        = item.Date,
                    Description = item.Description,
                    Amount      = item.Amount
                });
            }

            foreach (var item in reqsToUpdate)
            {
                var dbObj = update.Deposits.FirstOrDefault(d => d.ToolDepositId == item.ToolDepositId);
                if (dbObj == null)
                {
                    continue;
                }

                dbObj.Date        = item.Date;
                dbObj.Description = item.Description;
                dbObj.Amount      = item.Amount;
                dbObj.DeleteInd   = item.DeleteInd;
            }
        }
Exemple #3
0
        private void SetAccountsAndUpdate(IAirProToolDto tool, AirProToolEntityModel update)
        {
            // Check Update.
            if (update == null || tool.ToolId == null)
            {
                return;
            }

            var reqsToDelete = update.Accounts
                               ?.Where(x => tool.AccountAssignments.All(y => y != x.AccountGuid))
                               .ToList() ?? new List <AirProToolAccountEntityModel>();

            var reqsToAdd = tool.AccountAssignments
                            ?.Where(x => update.Accounts.All(y => y.AccountGuid != x))
                            .ToList() ?? new List <Guid>();

            foreach (var item in reqsToDelete)
            {
                item.UpdatedByUserGuid = User.UserGuid;
                item.UpdatedDt         = DateTimeOffset.UtcNow;
            }
            Db.SaveChanges();

            foreach (var item in reqsToDelete)
            {
                update.Accounts?.Remove(item);
            }

            foreach (var item in reqsToAdd)
            {
                update.Accounts?.Add(new AirProToolAccountEntityModel
                {
                    AccountGuid       = item,
                    ToolId            = tool.ToolId.Value,
                    CreatedByUserGuid = User.UserGuid
                });
            }
        }
Exemple #4
0
        private void SetShopsAndUpdate(IAirProToolDto tool, AirProToolEntityModel update)
        {
            // Check Update.
            if (update == null || tool.ToolId == null)
            {
                return;
            }

            var reqsToDelete = update.Shops
                               ?.Where(x => tool.ShopAssignments.All(y => y.Key != x.ShopGuid))
                               .ToList() ?? new List <AirProToolShopEntityModel>();

            var reqsToAdd = tool.ShopAssignments
                            ?.Where(x => update.Shops.All(y => y.ShopGuid != x.Key))
                            .ToList() ?? new List <KeyValuePair <Guid, string> >();

            foreach (var item in reqsToDelete)
            {
                item.UpdatedByUserGuid = User.UserGuid;
                item.UpdatedDt         = DateTimeOffset.UtcNow;
            }
            Db.SaveChanges();

            foreach (var item in reqsToDelete)
            {
                update.Shops?.Remove(item);
            }

            foreach (var item in reqsToAdd)
            {
                update.Shops?.Add(new AirProToolShopEntityModel
                {
                    ShopGuid          = item.Key,
                    ToolId            = tool.ToolId.Value,
                    CreatedByUserGuid = User.UserGuid
                });
            }
        }