Exemplo n.º 1
0
        private void SyncSpoilChanges(SpoilDto spoilDto, TableDependency.Enums.ChangeType changeType)
        {
            var unsyncedSpoil = GetUnSyncSpoilBy(spoilDto.SpoilId);

            if (unsyncedSpoil == null && changeType != ChangeType.Delete)
            {
                return;
            }

            switch (changeType)
            {
            case ChangeType.Delete:
            {
                String spoilId       = spoilDto.SpoilId.ToString();
                var    existingSpoil = _spoilSyncSvc.FirstOrDefault(t => t.TransactionRefNo == spoilId);

                if (existingSpoil != null)
                {
                    existingSpoil.IsDeleted = true;
                    Spoil.Extend(unsyncedSpoil, existingSpoil);
                    _spoilSyncSvc.Update(existingSpoil);
                }
                break;
            }

            case TableDependency.Enums.ChangeType.Insert:
            {
                unsyncedSpoil.RefModifiedDate = unsyncedSpoil.RefCreatedDate;

                var dbTrt = _spoilSyncSvc.FirstOrDefault(t => t.TransactionRefNo == unsyncedSpoil.TransactionRefNo);

                if (dbTrt == null)
                {
                    unsyncedSpoil.ModifiedOnUtc = unsyncedSpoil.CreatedOnUtc = DateTime.UtcNow;
                    _spoilSyncSvc.Add(unsyncedSpoil);
                }
                else
                {
                    Spoil.Extend(unsyncedSpoil, dbTrt);
                    _spoilSyncSvc.Update(dbTrt);
                }
                break;
            }

            case TableDependency.Enums.ChangeType.Update:
            {
                if (spoilDto.IsDeleted)
                {
                    goto case ChangeType.Delete;
                }

                var dbTrt = _spoilSyncSvc.FirstOrDefault(t => t.TransactionRefNo == unsyncedSpoil.TransactionRefNo);

                if (dbTrt == null)
                {
                    unsyncedSpoil.CreatedOnUtc  = DateTime.UtcNow;
                    unsyncedSpoil.ModifiedOnUtc = DateTime.UtcNow;
                    Log.Warning(String.Format("Spoil with TransactionRefNo ({0}) couldn't be retreived for update.", unsyncedSpoil.TransactionRefNo));
                    Log.Information(String.Format("Adding Spoil with TransactionRefNo ({0}) to sync table as newly created.", unsyncedSpoil.StockRefNo));
                    _spoilSyncSvc.Add(unsyncedSpoil);
                }
                else
                {
                    Spoil.Extend(unsyncedSpoil, dbTrt);
                    _spoilSyncSvc.Update(dbTrt);
                }

                break;
            }

            case TableDependency.Enums.ChangeType.None:
            default:
                break;
            }
        }
Exemplo n.º 2
0
        private void SyncTransactionChanges(OrderDetailDto trtItem, TableDependency.Enums.ChangeType changeType)
        {
            var trt = GetSyncTransactionBy(trtItem.OrderDetailUId, null);

            if (trt == null && changeType != ChangeType.Delete)
            {
                return;
            }

            switch (changeType)
            {
            case ChangeType.Delete:
            {
                String ordtUId = trtItem.OrderDetailUId.ToString();
                var    dbTrt   = _trtSyncSvc.FirstOrDefault(t => ordtUId.Equals(t.StockRefNo, StringComparison.InvariantCultureIgnoreCase));

                if (dbTrt != null)
                {
                    dbTrt.IsDeleted = true;
                    Transaction.Extend(trt, dbTrt);
                    _trtSyncSvc.Update(dbTrt);
                }

                break;
            }

            case TableDependency.Enums.ChangeType.Insert:
            {
                trt.RefModifiedDate = trt.RefCreatedDate;

                var dbTrt = _trtSyncSvc.FirstOrDefault(t => t.StockRefNo == trt.StockRefNo);

                if (dbTrt == null)
                {
                    trt.ModifiedOnUtc = trt.CreatedOnUtc = DateTime.UtcNow;
                    _trtSyncSvc.Add(trt);
                }
                else
                {
                    Transaction.Extend(trt, dbTrt);
                    _trtSyncSvc.Update(dbTrt);
                }
                break;
            }

            case TableDependency.Enums.ChangeType.Update:
            {
                if (trtItem.IsDeleted)
                {
                    goto case ChangeType.Delete;
                }

                trt.IsDeleted = true;

                var dbTrt = _trtSyncSvc.FirstOrDefault(t => t.StockRefNo == trt.StockRefNo);

                if (dbTrt == null)
                {
                    trt.CreatedOnUtc  = DateTime.UtcNow;
                    trt.ModifiedOnUtc = DateTime.UtcNow;
                    Log.Warning(String.Format("Transaction with stock ref no ({0}) couldn't be retreive to update", trt.StockRefNo));
                    Log.Information(String.Format("Adding transaction with stock ref no ({0}) to sync table as newly created", trt.StockRefNo));
                    _trtSyncSvc.Add(trt);
                }
                else
                {
                    Transaction.Extend(trt, dbTrt);
                    _trtSyncSvc.Update(dbTrt);
                }

                break;
            }

            case TableDependency.Enums.ChangeType.None:
            default:
                break;
            }
        }