コード例 #1
0
        public List <Model.Common.Customer> GetCustomer()
        {
            List <Model.Common.Customer> Items = new List <Model.Common.Customer>();

            try
            {
                using (var dBContext = new CustomerReportContext())
                {
                    Model.Common.Customer cust;
                    foreach (var it in dBContext.TblCustomer)
                    {
                        cust              = new Model.Common.Customer();
                        cust.CustomerNo   = it.CustomerNo;
                        cust.CustomerName = it.CustomerName;
                        Items.Add(cust);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(Items);
        }
コード例 #2
0
        public int AddCustomerData(Model.Common.Customer CustomerModel, string CustomerNo)
        {
            List <Model.Common.Customer> Items = new List <Model.Common.Customer>();

            int returnVal = 0;

            try
            {
                using (var dBContext = new CustomerReportContext())
                {
                    Model.Common.Customer get;
                    foreach (var it in dBContext.TblCustomer)
                    {
                        get              = new Model.Common.Customer();
                        get.CustomerNo   = it.CustomerNo;
                        get.CustomerName = it.CustomerName;
                        Items.Add(get);
                    }

                    TblCustomer Cust;
                    //Add record
                    Cust              = new TblCustomer();
                    Cust.CustomerNo   = CustomerModel.CustomerNo;
                    Cust.CustomerName = CustomerModel.CustomerName;

                    CustomerNo = Cust.CustomerNo;

                    bool CustNo = Items.Any(asd => asd.CustomerNo == CustomerNo);
                    if (CustNo == true)
                    {
                        returnVal = -1;
                    }

                    if (CustNo == false)
                    {
                        dBContext.TblCustomer.Add(Cust);
                        returnVal = dBContext.SaveChanges();
                    }

                    //returnVal = dBContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(returnVal);
        }