コード例 #1
0
        public List <CustomerDC> Post([FromBody] CustomerDC customerDc)
        {
            if (customerDc == null)
            {
                return(new List <CustomerDC>());
            }

            switch (customerDc.event_key)
            {
            case "search": {
                return(CustomerManager.customers_search(_context, customerDc));
            }

            case "new":
            {
                return(_context.Customers
                       .Where(p => (p.Branch != null && customerDc.branch != null) && p.Branch.Id == customerDc.branch.branch_id)
                       .Select(p => new CustomerDC {
                        customer_id = p.Id, customerName = p.Name
                    }).ToList());
            }

            default:
                break;
            }
            return(new List <CustomerDC>());
        }
コード例 #2
0
 public CustomerDC GetCustomerById()
 {
     using (var db = new SystemContext())
     {
         var identity = ServiceSecurityContext.Current.PrimaryIdentity.Name;
         System.Diagnostics.Debug.Print(">>> db: " + db.Database.Connection.ConnectionString);
         System.Diagnostics.Debug.Print(">>> result size: " + db.Customers.Count());
         var temp = db.Customers.FirstOrDefault((cust) => cust.Identity.Equals(identity));
         if (temp != null)
         {
             var customer = new CustomerDC();
             customer.Identity = temp.Identity;
             customer.Name     = temp.Name;
             customer.Fund     = temp.Fund;
             customer.Profs    = temp.Profs;
             return(customer);
         }
         return(null);
     }
 }
コード例 #3
0
        public List <CustomerDC> GetAllCustomer()
        {
            SystemContext db        = new SystemContext();
            var           customers = new List <CustomerDC>();
            var           identity  = ServiceSecurityContext.Current.PrimaryIdentity.Name;

            System.Diagnostics.Debug.Print(identity);
            System.Diagnostics.Debug.Print(">>> enter GetAllCustomer method.");
            System.Diagnostics.Debug.Print(">>> db: " + db.Database.Connection.ConnectionString);
            System.Diagnostics.Debug.Print(">>> result size: " + db.Customers.Count());
            foreach (var temp in db.Customers.ToList())
            {
                var customer = new CustomerDC();
                customer.Name  = temp.Name;
                customer.Fund  = temp.Fund;
                customer.Profs = temp.Profs;
                customers.Add(customer);
            }
            return(customers);
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: radtek/Xml_Loader
        private void tvDatabaseView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem selectedNode = tvDatabaseView.SelectedItem as TreeViewItem;

            if (connected && selectedNode != null && selectedNode.Parent as TreeViewItem != null)
            {
                try {
                    String   _customerName = (selectedNode.Parent as TreeViewItem).Header.ToString();
                    String   _carName;
                    DateTime _version;
                    SplitNameVersion(selectedNode, out _carName, out _version);
                    customer = db.GetCustomer(_customerName);
                    car      = db.GetCar(customer.customerId, _carName, _version);
                    var p = db.GetParamList(car.carId);
                    param = p;
                    dgvDatabaseParam.ItemsSource = param;
                    signal = db.GetSignalList(car.carId);
                    dgcDatabaseSignal.ItemsSource = signal;
                    databaseCarSelected           = true;
                } catch (Exception ex) {
                    NoConnection("tvDatabaseView_MouseDoubleClick(object sender, MouseEventArgs e)", ex);
                }
            }
        }
コード例 #5
0
        //This method is shared between create and save
        private ActionResult UpdateCustomer()
        {
            // Get the updated model
            var model = GetUpdatedModel();

            // Test to see if there are any errors
            var errors = ModelState
                         .Where(x => x.Value.Errors.Count > 0)
                         .Select(x => new { x.Key, x.Value.Errors[0].ErrorMessage })
                         .ToArray();

            //Set flags false
            SetFlagsFalse(model);

            // Test to see if the model has validated correctly
            if (ModelState.IsValid)
            {
                // Create service instance
                IUcbService sc = UcbService;

                //Attempt update
                try
                {
                    // Map model to data contract
                    CustomerDC CustomerItem = Mapper.Map <CustomerDC>(model.CustomerItem);

                    CustomerVMDC returnedObject = null;

                    if (null == model.CustomerItem.Code || model.CustomerItem.Code == Guid.Empty)
                    {
                        // Call service to create new Customer item
                        returnedObject = sc.CreateCustomer(CurrentUser, CurrentUser, appID, "", CustomerItem);
                    }
                    else
                    {
                        // Call service to update Customer item
                        returnedObject = sc.UpdateCustomer(CurrentUser, CurrentUser, appID, "", CustomerItem);
                    }

                    // Close service communication
                    ((ICommunicationObject)sc).Close();

                    // Retrieve item returned by service
                    var createdCustomer = returnedObject.CustomerItem;

                    // Map data contract to model
                    model.CustomerItem = Mapper.Map <CustomerModel>(createdCustomer);

                    //After creation some of the fields are display only so we need the resolved look up nmames
                    ResolveFieldCodesToFieldNamesUsingLists(model);

                    // Set access context to Edit mode
                    model.AccessContext = CustomerAccessContext.Edit;

                    // Save version of item returned by service into session
                    sessionManager.CustomerServiceVersion = model.CustomerItem;
                    sessionManager.CurrentCustomer        = model.CustomerItem;

                    // Remove the state from the model as these are being populated by the controller and the HTML helpers are being populated with
                    // the POSTED values and not the changed ones.
                    ModelState.Clear();
                    model.Message = Resources.MESSAGE_UPDATE_SUCCEEDED;
                }
                catch (Exception e)
                {
                    // Handle the exception
                    string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc);
                    model.Message = message;

                    return(View(model));
                }
            }

            return(View(model));
        }
コード例 #6
0
ファイル: XmlParser.cs プロジェクト: radtek/Xml_Loader
        public static void SaveToXml(CustomerDC customer, CarDC car, List <ParamDC> param, List <SignalDC> signal)
        {
            XmlNode node         = GetRootNode();
            XmlNode customerNode = null;

            foreach (XmlNode customerChechNode in node)
            {
                if (customerChechNode.Name == customer.name)
                {
                    customerNode = customerChechNode;
                    break;
                }
            }

            if (customerNode == null)
            {
                customerNode = node.AppendChild(XD.CreateElement(customer.name));
            }

            // Checking if car version already exists
            foreach (XmlNode carNode in customerNode)
            {
                if (carNode.Name == car.name)
                {
                    if (carNode.Attributes["version"] != null && ToDateTime(carNode.Attributes["version"].Value) == car.version)
                    {
                        if (MessageBox.Show("Car already exists.\nOverride existing car?", "Conflict", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                        {
                            customerNode.RemoveChild(carNode);
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }

            XmlNode      newCar     = customerNode.AppendChild(XD.CreateElement(car.name));
            XmlAttribute newVersion = newCar.Attributes.Append(XD.CreateAttribute("version"));

            newVersion.InnerText = car.version.ToString(VERSION_FORMAT);

            XmlNode newParameters = newCar.AppendChild(XD.CreateElement("Parameters"));
            String  _subPath      = param[0].subPath;
            XmlNode subPathNode   = newParameters.AppendChild(XD.CreateElement(_subPath));

            foreach (var p in param)
            {
                if (p.subPath != _subPath)
                {
                    _subPath    = p.subPath;
                    subPathNode = newParameters.AppendChild(XD.CreateElement(_subPath));
                }
                XmlNode paramAtt = subPathNode.AppendChild(XD.CreateElement(p.path));
                paramAtt.InnerText = p.value.ToString();
            }

            XmlNode newSignals = newCar.AppendChild(XD.CreateElement("Signals"));

            foreach (var p in signal)
            {
                XmlNode newSignal = newSignals.AppendChild(XD.CreateElement(p.type));
                XmlNode typeAtt   = newSignal.AppendChild(XD.CreateElement("type"));
                typeAtt.InnerText = p.type;
                XmlNode idAtt = newSignal.AppendChild(XD.CreateElement("id"));
                idAtt.InnerText = p.id.ToString();
                XmlNode startbitAtt = newSignal.AppendChild(XD.CreateElement("startbit"));
                startbitAtt.InnerText = p.startbit.ToString();
                XmlNode sizeAtt = newSignal.AppendChild(XD.CreateElement("size"));
                sizeAtt.InnerText = p.size.ToString();
                XmlNode formatAtt = newSignal.AppendChild(XD.CreateElement("format"));
                formatAtt.InnerText = p.format == "I" ? "intel" : "motorola";
                XmlNode signedAtt = newSignal.AppendChild(XD.CreateElement("signed"));
                signedAtt.InnerText = p.signed == "S" ? "1" : "0";
                XmlNode factorAtt = newSignal.AppendChild(XD.CreateElement("factor"));
                factorAtt.InnerText = p.factor.ToString();
                XmlNode offsetAtt = newSignal.AppendChild(XD.CreateElement("offset"));
                offsetAtt.InnerText = p.offset.ToString();
                XmlNode minAtt = newSignal.AppendChild(XD.CreateElement("min"));
                minAtt.InnerText = p.min.ToString();
                XmlNode maxAtt = newSignal.AppendChild(XD.CreateElement("max"));
                maxAtt.InnerText = p.max.ToString();
                XmlNode matchAtt = newSignal.AppendChild(XD.CreateElement("match"));
                matchAtt.InnerText = p.match.ToString();
            }

            XD.Save(FILE_PATH);
        }
コード例 #7
0
        /// <summary>
        ///  Create a Customer
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public CustomerVMDC CreateCustomer(string currentUser, string user, string appID, string overrideID, CustomerDC dc, IRepository <Customer> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService)
        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (null == dc)
                {
                    throw new ArgumentOutOfRangeException("dc");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    // Create a new ID for the Customer item
                    dc.Code = Guid.NewGuid();

                    // Map data contract to model
                    Customer destination = mappingService.Map <CustomerDC, Customer>(dc);

                    // Add the new item
                    dataRepository.Add(destination);

                    // Commit unit of work
                    uow.Commit();

                    // Map model back to data contract to return new row id.
                    dc = mappingService.Map <Customer, CustomerDC>(destination);
                }

                // Create aggregate data contract
                CustomerVMDC returnObject = new CustomerVMDC();

                // Add new item to aggregate
                returnObject.CustomerItem = dc;

                return(returnObject);
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
コード例 #8
0
        /// <summary>
        /// Retrieve a Customer with associated lookups
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        /// <returns></returns>
        public CustomerVMDC GetCustomer(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <Customer> dataRepository
                                        , IRepository <RelationshipToCustomer> relationshipToCustomerRepository
                                        , IExceptionManager exceptionManager, IMappingService mappingService)

        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    CustomerDC destination = null;

                    // If code is null then just return supporting lists
                    if (!string.IsNullOrEmpty(code))
                    {
                        // Convert code to Guid
                        Guid codeGuid = Guid.Parse(code);

                        // Retrieve specific Customer
                        Customer dataEntity = dataRepository.Single(x => x.Code == codeGuid);

                        // Convert to data contract for passing through service interface
                        destination = mappingService.Map <Customer, CustomerDC>(dataEntity);
                    }

                    IEnumerable <RelationshipToCustomer> relationshipToCustomerList = relationshipToCustomerRepository.GetAll(x => new { x.Description });

                    List <RelationshipToCustomerDC> relationshipToCustomerDestinationList = mappingService.Map <List <RelationshipToCustomerDC> >(relationshipToCustomerList);

                    // Create aggregate contract
                    CustomerVMDC returnObject = new CustomerVMDC();

                    returnObject.CustomerItem = destination;
                    returnObject.RelationshipToCustomerList = relationshipToCustomerDestinationList;

                    return(returnObject);
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
コード例 #9
0
        /// <summary>
        /// Create a Customer
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        public CustomerVMDC CreateCustomer(string currentUser, string user, string appID, string overrideID, CustomerDC dc)
        {
            // Create unit of work
            IUnitOfWork uow = new UnitOfWork(currentUser);

            // Create repository
            Repository <Customer> dataRepository = new Repository <Customer>(uow.ObjectContext, currentUser, user, appID, overrideID);

            //Create ExceptionManager
            IExceptionManager exceptionManager = new ExceptionManager();

            //Create MappingService
            IMappingService mappingService = new MappingService();


            // Call overload with injected objects
            return(CreateCustomer(currentUser, user, appID, overrideID, dc, dataRepository, uow, exceptionManager, mappingService));
        }
コード例 #10
0
        public static List <CustomerDC> customers_search(Model.Configuration.Context _context, CustomerDC customer)
        {
            var clientes = _context.Customers;

            var clientesfiltrados = clientes.Where
                                        (p =>
                                        (customer.customer_id == 0 || customer.customer_id > 0 && customer.customer_id == p.Id) &&
                                        (customer.user_id == 0 || customer.user_id > 0 && customer.user_id == p.User.Id) &&
                                        (string.IsNullOrEmpty(customer.customerName) || (!string.IsNullOrEmpty(customer.customerName) && customer.customerName == p.Name)) &&
                                        (customer.branch == null || (p.Branch != null && p.Branch.Id == customer.branch.branch_id))

                                        );

            var selec = clientesfiltrados.Select(p => new CustomerDC
            {
                customer_id  = p.Id,
                customerName = p.Name,
                branch       = p.Branch != null ? new BranchDC()
                {
                    branch_id = p.Branch.Id, branchName = p.Branch.Name
                } : null,
                user_id = p.User != null ? p.User.Id : 0
            }).ToList();

            return(selec);
        }