Exemple #1
0
        private static bool InsertAndUpdate <TModel, TIdentity>(
            UnitOfWorkWithReference <TModel, TIdentity> unitOfWork,
            ImportWorker <TModel> worker)
            where TModel : class, new()
        {
            foreach (var pair in worker.Models)
            {
                TModel    product        = pair.Value;
                TIdentity importedUnique = unitOfWork.GetIdentity(product);

                TModel target = null;
                if (unitOfWork.All.TryGetValue(importedUnique, out target))
                {
                    Model.CopyTo(product, target, false);
                    unitOfWork.RegisterDirty(target);
                }
                else
                {
                    unitOfWork.RegisterNew(product);
                }
            }
            Model.SetUpdateBy(unitOfWork.New.Concat(unitOfWork.Dirty), worker.LoginUserId);

            return(worker.Models.Any());
        }
Exemple #2
0
        private static bool Replace <TModel, TIdentity>(
            UnitOfWorkWithReference <TModel, TIdentity> unitOfWork,
            ImportWorker <TModel> worker)
            where TModel : class, new()
        {
            foreach (var pair in worker.Models)
            {
                TModel    product        = pair.Value;
                TIdentity importedUnique = unitOfWork.GetIdentity(product);

                TModel target = null;
                if (unitOfWork.All.TryGetValue(importedUnique, out target))
                {
                    Model.CopyTo(product, target, false);
                    unitOfWork.RegisterDirty(target);
                }
                else
                {
                    unitOfWork.RegisterNew(product);
                }
            }
            IEnumerable <TModel> newAndDirty = unitOfWork.Dirty.Concat(unitOfWork.New);

            Model.SetUpdateBy(newAndDirty, worker.LoginUserId);
            foreach (TModel model in unitOfWork.All.Values.Except(newAndDirty))
            {
                unitOfWork.RegisterRemoved(model);
            }

            if (worker.RecordCount != worker.Models.Count)
            {
                worker.Models.Clear(); // 全件取込不可
            }

            return(worker.Models.Any());
        }