Ejemplo n.º 1
0
        public void SavePhysicalCount(PhysicalCountInfo physicalCount)
        {
            PhysicalCountInfo originalPhysicalCount = OpenPhysicalCount(physicalCount.Id);
            AuditTrailWrapper atw = new AuditTrailWrapper(AuditTrailWrapper.InvCount,
                                                          new object[][] { new object[] { originalPhysicalCount, physicalCount, AuditTrailWrapper.ExistingRecord } }, "Inventory Control");

            foreach (PhysicalCountInspectorInfo inspector in physicalCount.Inspectors)
            {
                PhysicalCountInspectorInfo originalInspector = originalPhysicalCount.Inspectors.Find(oi => oi.Id == inspector.Id);
                if (originalInspector == null)
                {
                    atw.AddChange(null, inspector, AuditTrailWrapper.NewRecord);
                }
                else
                {
                    atw.AddChange(originalInspector, inspector, AuditTrailWrapper.ExistingRecord);
                }
            }
            foreach (StackPhysicalCountInfo stack in originalPhysicalCount.Stacks)
            {
                StackPhysicalCountInfo originalStack = physicalCount.Stacks.Find(os => os.Id == stack.Id);
                if (originalStack == null)
                {
                    atw.AddChange(null, stack, AuditTrailWrapper.NewRecord);
                }
                else
                {
                    atw.AddChange(originalStack, stack, AuditTrailWrapper.ExistingRecord);
                }
            }

            Dictionary <string, object> contextParameters = new Dictionary <string, object>();

            contextParameters.Add("CurrentUser", new Guid(SystemLookup.LookupSource.GetLookup("CurrentUser")["Id"]));
            Queue <object> queue = new Queue <object>(new object[] { physicalCount });

            foreach (PhysicalCountInspectorInfo inspector in physicalCount.Inspectors)
            {
                queue.Enqueue(inspector);
            }
            foreach (StackPhysicalCountInfo stack in physicalCount.Stacks)
            {
                queue.Enqueue(stack);
            }
            try
            {
                SqlTransaction transaction = PersistenceTransactionFactory.CreatePersistenceTransaction().Persist(
                    queue, contextParameters);
                if (!atw.Save())
                {
                    transaction.Rollback();
                    throw new Exception("Failed to save audit trail!");
                }
                transaction.Commit();
            }
            catch (Exception ex)
            {
                throw new Exception("Physical Count couldn't be saved to the database", ex);
            }
        }
Ejemplo n.º 2
0
 public void Copy(PhysicalCountInspectorInfo inspector)
 {
     Id = inspector.Id;
     PhysicalCountId = inspector.PhysicalCountId;
     UserId          = inspector.UserId;
     IsSupervisor    = inspector.IsSupervisor;
 }
Ejemplo n.º 3
0
 public void AddInspector(PhysicalCountInfo physicalCount, PhysicalCountInspectorInfo inspector)
 {
     if (physicalCount.Inspectors.Any(i => (i.UserId == inspector.UserId) || (i.IsSupervisor && inspector.IsSupervisor)))
     {
         throw new Exception("Invalid Inspector : Inspector shall not be duplicated and only 1 supervisor is admitted");
     }
     physicalCount.Inspectors.Add(inspector);
 }