Exemplo n.º 1
0
        private void idBtnSave_Click(object sender, EventArgs e)
        {
            var objCustInfo  = GetCustomerInfoFromTextBox();
            var ErrorCounter = 0;
            var ErrorMessage = "Following fields should not be empty \n\n";

            if (string.IsNullOrEmpty(objCustInfo.CompanyName))
            {
                ErrorCounter++;
                ErrorMessage += ErrorCounter.ToString() + "] " + "Please Enter Company Name \n";
            }

            if (string.IsNullOrEmpty(objCustInfo.Address))
            {
                ErrorCounter++;
                ErrorMessage += ErrorCounter.ToString() + "] " + "Please Enter Address \n";
            }

            if (string.IsNullOrEmpty(objCustInfo.Contact))
            {
                ErrorCounter++;
                ErrorMessage += ErrorCounter.ToString() + "] " + "Please Enter Contact \n";
            }

            if (string.IsNullOrEmpty(objCustInfo.StateName))
            {
                ErrorCounter++;
                ErrorMessage += ErrorCounter.ToString() + "] " + "Please Enter State Name \n";
            }

            if (ErrorCounter > 0)
            {
                MessageBox.Show(ErrorMessage, "Warning !...");
                return;
            }



            if (string.IsNullOrEmpty(objCustInfo.Id))
            {
                var dt = MastersBl.GetFilteredCustomerList("CompanyName", idTxtCompanyName.Text.Trim());
                if (dt.Rows.Count > 0)
                {
                    MessageBox.Show("Customer with company name '" + idTxtCompanyName.Text.Trim() + "' already exist.");
                    return;
                }
                CustomerBl.SaveCustomer(objCustInfo);
            }
            else
            {
                CustomerBl.UpdateCustomer(objCustInfo);
            }
            FormCancelButton = true;
            if (InitFromMenu != true)
            {
                MastersCustomers obj = new MastersCustomers();
                obj.Show();
            }
            this.Close();
        }
Exemplo n.º 2
0
        private void idBtnEdit_Click(object sender, EventArgs e)
        {
            if (IsDgvRowsPresent())
            {
                var rowIndex    = idDgvMastersCustomer.SelectedCells[0].RowIndex;
                var id          = idDgvMastersCustomer.Rows[rowIndex].Cells[0].Value.ToString();
                var ObjCustInfo = CustomerBl.GetCustomerPerId(id);

                Customers obj = new Customers(ObjCustInfo);
                obj.Show();
                this.Close();
            }
        }
        public CustomerBl AddCustomer(CustomerBl customerBl)
        {
            if (customerBl.CustomerId.GetValueOrDefault() != 0)
            {
                throw new ArgumentException("customerBl cannot define it's own id");
            }

            var customer = _mapper.Map <Customer>(customerBl);

            _context.Customer.Add(customer);
            _context.SaveChanges();

            return(_mapper.Map <CustomerBl>(customer));
        }
Exemplo n.º 4
0
        public OperationResult EditCustomerProfile(CustomerProfileModel model)
        {
            OperationResult or;

            try
            {
                or = new CustomerBl().EditCustomerProfile(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(or);
        }
Exemplo n.º 5
0
        public OperationResult GetCustomerProfile(int id)
        {
            OperationResult or;

            try
            {
                or = new CustomerBl().GetCustomerProfile(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(or);
        }
Exemplo n.º 6
0
 private void idBtnDelete_Click(object sender, EventArgs e)
 {
     if (IsDgvRowsPresent())
     {
         var          rowIndex     = idDgvMastersCustomer.SelectedCells[0].RowIndex;
         var          id           = idDgvMastersCustomer.Rows[rowIndex].Cells[0].Value.ToString();
         var          Customer     = idDgvMastersCustomer.Rows[rowIndex].Cells[1].Value.ToString();
         DialogResult dialogResult = MessageBox.Show("Are you sure to delete customer : " + Customer + "\nThe record will be permanently deleted", "Delete Warning !...", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             CustomerBl.DeleteCustomer(id);
             RefreshDgv();
         }
     }
 }
        public void DeleteCustomer(CustomerBl customerBl)
        {
            if (customerBl == null)
            {
                throw new ArgumentException("customerBl cannot be null");
            }

            var customer = _context.Customer.SingleOrDefault(c => c.CustomerId == customerBl.CustomerId);

            if (customer == null)
            {
                throw new ArgumentException(String.Format("customer {0} does not exist", customerBl.CustomerId));
            }

            _context.Customer.Remove(customer);
            _context.SaveChanges();
        }
        public CustomerBl UpdateCustomer(CustomerBl customerBl)
        {
            if (customerBl == null)
            {
                throw new ArgumentException("customerBl cannot be null");
            }

            var customer = _context.Customer.SingleOrDefault(c => c.CustomerId == customerBl.CustomerId);

            if (customer == null)
            {
                throw new ArgumentException(String.Format("customer {0} does not exist", customerBl.CustomerId));
            }

            _mapper.Map(customerBl, customer);
            _context.SaveChanges();

            return(_mapper.Map <CustomerBl>(customer));
        }