Exemplo n.º 1
0
        public void SaveInternalOrder(ClassifierViewModel model)
        {
            var u = new UnitOfWork();

            if (model.Id > 0)
            {
                var io        = u.Classifier.GetAll().FirstOrDefault(w => w.Id == model.Id);
                var ioMapping = u.IOMapping.GetAll().FirstOrDefault(f => f.InternalOrder.Id == io.Id);
                if (io != null)
                {
                    if (io.Name != model.Name || io.Code != model.Code || io.Active != model.Active)
                    {
                        io.Name   = model.Name;
                        io.Code   = model.Code;
                        io.Active = model.Active;

                        u.Classifier.Edit(io);
                        u.Classifier.Save();
                    }

                    if (ioMapping != null && (ioMapping.Brand.Id != model.Level2Id || ioMapping.Client.Id != model.Level1Id))
                    {
                        var brand  = u.Classifier.GetAll().FirstOrDefault(w => w.Id == model.Level2Id);
                        var client = u.Classifier.GetAll().FirstOrDefault(w => w.Id == model.Level1Id);
                        ioMapping.Brand  = brand;
                        ioMapping.Client = client;
                        ioMapping.Active = model.Active;
                        u.IOMapping.Edit(ioMapping);
                        u.IOMapping.Save();
                    }
                }
            }
            else
            {
                var type = u.ClassifierType.GetAll().FirstOrDefault(w => w.Name == model.Type);
                if (type == null)
                {
                    return;
                }
                var newClassif = new Classifier()
                {
                    Name = model.Name, Code = model.Code, Active = model.Active, ClassifierType = type, DateFrom = DateTime.Now, DateTo = DateTime.Now
                };
                u.Classifier.Add(newClassif);
                u.Classifier.Save();
                var brand        = u.Classifier.GetAll().FirstOrDefault(w => w.Id == model.Level2Id);
                var client       = u.Classifier.GetAll().FirstOrDefault(w => w.Id == model.Level1Id);
                var newIOMapping = new IOMapping()
                {
                    InternalOrder = newClassif, Client = client, Brand = brand, Active = model.Active
                };
                u.IOMapping.Add(newIOMapping);
                u.IOMapping.Save();
            }
        }
Exemplo n.º 2
0
        // Removes the selected item.
        private void RemoveSelected()
        {
            IOMapping selected = m_selectedIOMapping;

            if (string.IsNullOrEmpty(m_selectedCalculatorName))
            {
                return;
            }

            if ((object)selected == null)
            {
                return;
            }

            RemoveMapping();
            DeleteOutputMeasurement(m_selectedIOMapping.OutputKey);
            Load();
        }
Exemplo n.º 3
0
        // Removes the selected item.
        private void RemoveSelected()
        {
            IOMapping selected = m_selectedIOMapping;

            if ((object)m_calculator == null)
            {
                return;
            }

            if ((object)selected == null)
            {
                return;
            }

            RemoveMapping();
            DeleteOutputMeasurement(m_selectedIOMapping.OutputKey);
            Load();
        }