Example #1
0
        public Customer Get(CustomerNumber customerNumber)
        {
            var customerDocument = customersCollection.Find(document => document.Number == customerNumber)
                                   .FirstOrDefault();

            return(customerDocument.AsCustomer());
        }
Example #2
0
 // sets the Customer up to a array used to show data in the listview as a listviewitem
 public string[] GetListViewItemRange()
 {
     string[] arr = new string[11]
     {
         CustomerNumber.ToString(), FirstName, LastName, EmailAddress.Print(), AccountBalance.ToString(), CustAdresse.PostCode.ToString(), CustAdresse.City, CustAdresse.Street, CustAdresse.StreetNr.ToString(),
              LastAccess.ToShortDateString(), ""
     };
     return(arr);
 }
        public IHttpActionResult PostCustomer(CustomerViewModel customerViewModel)
        {
            customerViewModel.CreatedOn = DateTime.Now;
            customerViewModel.CreatedBy = User.Identity.GetUserName();

            //var errors = ModelState.Values.SelectMany(v => v.Errors);
            //can not apply modelstate.isvalid because it is looking for ID in model & giving error.

            if (string.IsNullOrEmpty(customerViewModel.Name))
            {
                return(BadRequest(ModelState));
            }

            //i should do transactions here to make sure all recrrds insserts correctly
            var customer = new Customer()
            {
                Customer_Name    = customerViewModel.Name,
                Customer_Details = customerViewModel.Details,
                Customer_Address = customerViewModel.Address,
                Customer_Contact = customerViewModel.Contact,
                Is_Active        = customerViewModel.IsActive,
                Created_By       = customerViewModel.CreatedBy,
                Created_On       = customerViewModel.CreatedOn
            };

            db.Customers.Add(customer);
            db.SaveChanges();

            //adding customer numbers here
            foreach (var customerNumberViewModel in customerViewModel.CustomerNumbers)
            {
                var customerNumber = new CustomerNumber();

                customerNumber.Customer_Id_Fk          = customer.Customer_Id_Pk;
                customerNumber.Customer_Number_Details = customerNumberViewModel.NumberDetail;
                customerNumber.Customer_Number_Value   = customerNumberViewModel.NumberValue;
                customerNumber.Created_By = User.Identity.GetUserName();
                customerNumber.Created_On = DateTime.Now;

                db.CustomerNumbers.Add(customerNumber);
                db.SaveChanges();
            }

            return(Created(new Uri(Request.RequestUri + "/" + customer.Customer_Id_Pk), customerViewModel));
        }
Example #4
0
        /// <summary>
        /// Creates the POST request.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="serviceUrl"></param>
        /// <param name="obj"></param>
        TResponse SendRequest <TRequest, TResponse>(string serviceUrl, TRequest obj)
        {
            var data     = XmlUtils.Serialize <TRequest>(obj);
            var address  = new Uri(serviceUrl);
            var byteData = UTF8Encoding.UTF8.GetBytes(data);
            var key      = Hash(string.Format("{0}{1:yyyyMMdd}{2}", IpAddress, DateTime.Now, AuthToken));
            var request  = WebRequest.Create(address) as HttpWebRequest;

            request.Method        = "POST";
            request.ContentType   = "application/xml";
            request.ContentLength = byteData.Length;
            request.Headers.Add("customerNo", CustomerNumber.ToString());
            request.Headers.Add("key", key);
            using (Stream postStream = request.GetRequestStream()) {
                postStream.Write(byteData, 0, byteData.Length);
            }
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) {
                using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) {
                    return(XmlUtils.Deserialize <TResponse>(reader));
                }
            }
        }
Example #5
0
 public string PrintCustomerCrypt()
 {
     return(Crypto.EncodeLine(new string[] { CustomerNumber.ToString(), FirstName, LastName, EmailAddress.Print(), CustAdresse.ToCSVString(), LastAccess.ToShortDateString(), AccountBalance.ToString() }));
 }
        private void button1_Click(object sender, EventArgs e)
        {
            String Name, Mobile, Age, CustomerNumber;

            Name           = textBox1.Text;
            Mobile         = textBox2.Text;
            Age            = textBox3.Text;
            CustomerNumber = textBox4.Text;
            if (Name.Length == 0 || Name.Length > 30)
            {
                errorProvider1.SetError(textBox1, " Please Enter Valid Name ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else if (Mobile.Length == 0 || Mobile.Length > 30)
            {
                errorProvider1.SetError(textBox2, " Please Enter Valid Mobile ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else if (Age.Length == 0)
            {
                errorProvider1.SetError(textBox3, " Please Enter Valid Age ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else if (CustomerNumber.Length == 0)
            {
                errorProvider1.SetError(textBox4, " Please Enter Valid CustomerNumber ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else
            {
                con.Open();
                errorProvider1.Clear();
                cmd.Connection = con;
                SqlCommand myCommand = new SqlCommand("insert into Customers values ('" +
                                                      Name.ToString() + "','" + Mobile.ToString() + "','" + Int32.Parse(Age.ToString()) + "','" + Int32.Parse(CustomerNumber.ToString()) + "')", con);
                int success = myCommand.ExecuteNonQuery();
                if (success == 1)
                {
                    MessageBox.Show(success + " row has been inserted ");
                }
                con.Close();
            }
        }
 CustomerName ICustomerData.GetCustomerName(CustomerNumber number) => GetCustomerName(number);
 CustomerName GetCustomerName(CustomerNumber number)
 {
     return(CustomerData.GetCustomerName(number));
 }
        private void button1_Click(object sender, EventArgs e)
        {
            String ProductID, OrderID, ID, CustomerNumber, Amount, Price, ProductName;

            ProductID      = textBox1.Text;
            OrderID        = textBox2.Text;
            ID             = textBox3.Text;
            CustomerNumber = textBox4.Text;
            Amount         = textBox5.Text;
            Price          = textBox6.Text;
            ProductName    = textBox7.Text;
            if (ProductID.Length == 0 || ProductID.Length > 30)
            {
                errorProvider1.SetError(textBox1, " Please Enter Valid ProductID ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else if (OrderID.Length == 0 || OrderID.Length > 30)
            {
                errorProvider1.SetError(textBox2, " Please Enter Valid OrderID ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else if (ID.Length == 0 || ID.Length > 30)
            {
                errorProvider1.SetError(textBox3, " Please Enter Valid ID ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else if (CustomerNumber.Length == 0)
            {
                errorProvider1.SetError(textBox4, " Please Enter Valid CustomerID ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else if (Amount.Length == 0)
            {
                errorProvider1.SetError(textBox5, " Please Enter Valid Amount ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else if (Price.Length == 0)
            {
                errorProvider1.SetError(textBox6, " Please Enter Valid Price ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else if (ProductName.Length == 0 || ProductName.Length > 30)
            {
                errorProvider1.SetError(textBox7, " Please Enter Valid ProductName ");
                errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
            }
            else
            {
                con.Open();
                errorProvider1.Clear();
                cmd.Connection = con;
                SqlCommand myCommand = new SqlCommand("insert into Orders values ('" +
                                                      ProductID.ToString() + "','" + OrderID.ToString() + "','" + ID.ToString() + "','" + Int32.Parse(CustomerNumber.ToString())
                                                      + "','" + Int32.Parse(Amount.ToString()) + "','" + float.Parse(Price.ToString()) + "','" + ProductName.ToString() + "')", con);
                int success = myCommand.ExecuteNonQuery();
                if (success == 1)
                {
                    MessageBox.Show(success + " row has been inserted ");
                }
                con.Close();
            }
        }
 public override string ToString()
 {
     return(AccountNumber + "/" + CustomerNumber.ToString() + " - " + Message);
 }
        public IHttpActionResult PutCustomer(int id, CustomerViewModel customerViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customerViewModel.ID)
            {
                return(BadRequest());
            }


            try
            {
                var customer = db.Customers.Find(customerViewModel.ID);
                customer.Customer_Name    = customerViewModel.Name;
                customer.Customer_Details = customerViewModel.Details;
                customer.Customer_Address = customerViewModel.Address;
                customer.Customer_Contact = customerViewModel.Contact;
                customer.Is_Active        = customerViewModel.IsActive;
                customer.Modified_By      = User.Identity.GetUserName();
                customer.Modified_On      = DateTime.Now;

                db.Entry(customer).State = EntityState.Modified;

                db.SaveChanges();

                foreach (var customerNumberViewModel in customerViewModel.CustomerNumbers)
                {
                    var customerNumber = db.CustomerNumbers.Where(c => c.Customer_Id_Fk == customer.Customer_Id_Pk).Where(n => n.Customer_Number_Id_Pk == customerNumberViewModel.ID).FirstOrDefault();

                    if (customerNumber != null)
                    {
                        customerNumber.Customer_Number_Details = customerNumberViewModel.NumberDetail;
                        customerNumber.Customer_Number_Value   = customerNumberViewModel.NumberValue;
                        customerNumber.Modified_By             = User.Identity.GetUserName();
                        customerNumber.Modified_On             = DateTime.Now;

                        db.Entry(customerNumber).State = EntityState.Modified;

                        db.SaveChanges();
                    }
                    else if (customerNumber == null)
                    {
                        customerNumber = new CustomerNumber();

                        customerNumber.Customer_Id_Fk          = customer.Customer_Id_Pk;
                        customerNumber.Customer_Number_Details = customerNumberViewModel.NumberDetail;
                        customerNumber.Customer_Number_Value   = customerNumberViewModel.NumberValue;
                        customerNumber.Created_By = User.Identity.GetUserName();
                        customerNumber.Created_On = DateTime.Now;

                        db.CustomerNumbers.Add(customerNumber);

                        db.SaveChanges();
                    }
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public override string ToString()
 {
     return(CustomerNumber.ToString() + " - " + Message);
 }
Example #13
0
 public override int GetHashCode()
 {
     return(CustomerNumber.GetHashCode());
 }