Beispiel #1
0
        public CW2Response <ContactDto> save(ContactDto dto)
        {
            CW2Response <ContactDto> validated = validateSave(dto);

            if (validated.Status.Equals(AppConstant.ERROR))
            {
                Console.WriteLine("Validation Error : Saving contact failed");
                return(validated);
            }

            //save local copy
            CW2Response <ContactDto> saveDraftResponse = saveDraft(dto);

            if (saveDraftResponse.Status.Equals(AppConstant.ERROR))
            {
                Console.WriteLine("Saving Draft Failed..attepmpting the save on database");
            }

            //save data on DB

            Task saveToDbTask = Task.Run(() => {
                CW2Response <ContactDto> saveToDBResponse = saveOnDB(dto);
                if (saveToDBResponse.Status.Equals(AppConstant.SUCCESS))
                {
                    //saving data to database success.
                    //remove the local copy.
                    Console.WriteLine("Record saved into the database successfully.");
                    CW2Response <ContactDto> removeDraftResponse = removeDraft(saveDraftResponse.dto.Id);
                }
            });

            return(saveDraftResponse);
        }
Beispiel #2
0
        private CW2Response <ContactDto> validateSave(ContactDto dto)
        {
            CW2Response <ContactDto> response = new CW2Response <ContactDto>();

            response.Status = AppConstant.SUCCESS;
            return(response);
        }
Beispiel #3
0
        public CW2Response <TransactionDto> searchTransactionByCriteria(TransactionDto dto)
        {
            CW2Response <TransactionDto> response = new CW2Response <TransactionDto>();

            List <TransactionDto> transactionDtoList = new List <TransactionDto>();

            try
            {
                List <Transaction> transactionList = TransactionDao.Instance.searchTransactionByCriteria(dto);

                foreach (var transaction in transactionList)
                {
                    transactionDtoList.Add(TransactionTransformer.Instance.domainToDto(transaction));
                }

                response.Status = AppConstant.SUCCESS;
            }
            catch (CW2DatabaseUnavaiableException e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("Database not available..");
                response.Status = AppConstant.ERROR; //workin offline mode
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                response.Status = AppConstant.ERROR;
            }

            response.dataList = transactionDtoList;

            return(response);
        }
Beispiel #4
0
        public CW2Response <ContactDto> searchContactByCriteria(ContactDto dto)
        {
            CW2Response <ContactDto> response = new CW2Response <ContactDto>();

            List <ContactDto> contactDtoList = new List <ContactDto>();

            try
            {
                List <Contact> contactList = ContactDao.Instance.searchTransactionByCriteria(dto);

                foreach (var contact in contactList)
                {
                    contactDtoList.Add(ContactTransformer.Instance.domainToDto(contact));
                }

                response.Status = AppConstant.SUCCESS;
            }
            catch (CW2DatabaseUnavaiableException e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("Database not available..");
                response.Status = AppConstant.ERROR; //workin offline mode
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                response.Status = AppConstant.ERROR;
            }

            response.dataList = contactDtoList;

            return(response);
        }
Beispiel #5
0
        private CW2Response <ContactDto> saveOnDB(ContactDto dto)
        {
            CW2Response <ContactDto> response = new CW2Response <ContactDto>();

            try
            {
                Contact contact = null;

                if (dto.DbEntityId != 0) //Update
                {
                    contact = ContactDao.Instance.findById(dto.DbEntityId);
                    ContactTransformer.Instance.dtoToDomain(dto, contact);
                }
                else //create
                {
                    contact = new Contact();
                    ContactTransformer.Instance.dtoToDomain(dto, contact);
                    contact.Id = 0;
                }

                contact = ContactDao.Instance.save(contact);

                response.dto     = ContactTransformer.Instance.domainToDto(contact);
                response.Status  = AppConstant.SUCCESS;
                response.Message = "Contact saved successfully";
            }
            catch (Exception e)
            {
                response.Status  = AppConstant.ERROR;
                response.Message = "DB Error : Unable to persist contact entity";
                Console.WriteLine(e.StackTrace);
            }

            return(response);;
        }
Beispiel #6
0
        private void fetchDataByCriteria()
        {
            ContactDto dto = new ContactDto();

            if (txtName.Text.Trim().Length > 0)
            {
                dto.ContactName = txtName.Text;
            }

            if (cmbType.Text.Trim().Length > 0)
            {
                dto.Type = cmbType.Text;
            }

            var dataList = new ArrayList();

            dataGridContact.AutoGenerateColumns = false;

            //Add Draft data first
            CW2Response <ContactDto> response1 = ContactService.Instance.getAllContactsFromDataSet();

            dataList.AddRange(response1.dataList);

            CW2Response <ContactDto> response = ContactService.Instance.searchContactByCriteria(dto);

            dataList.AddRange(response.dataList);

            dataGridContact.DataSource = dataList;

            reset();
        }
Beispiel #7
0
        public CW2Response <ContactDto> getAllContactsFromDataSet()
        {
            CW2Response <ContactDto> response       = new CW2Response <ContactDto>();
            List <ContactDto>        contactDtoList = new List <ContactDto>();

            try
            {
                List <ContactRow> contactRows = ContactDataSetDao.Instance.getAllContacts();

                foreach (var contactRow in contactRows)
                {
                    contactDtoList.Add(ContactTransformer.Instance.dataSetRowToDto(contactRow));
                }
                response.Status = AppConstant.SUCCESS;
            }
            catch (Exception e)
            {
                response.Status  = AppConstant.ERROR;
                response.Message = "Internal System Failure";
                Console.WriteLine(e.StackTrace);
            }

            response.dataList = contactDtoList;
            return(response);
        }
Beispiel #8
0
        /*    private void onBtnDeleteClick(object sender, MouseEventArgs e)
         *  {
         *      var confirm = MessageBox.Show("Are you sure, you want to delete this transaction", "Confirm Transaction Delete", MessageBoxButtons.YesNo);
         *      if (confirm == DialogResult.Yes)
         *      {
         *          CW2Response<TransactionDto> response = TransactionService.Instance.removeDraft(model.Id);
         *          MessageBox.Show(response.Message);
         *          populateGrid();
         *      }
         *  }*/

        private void onBtnDeleteClick(object sender, EventArgs e)
        {
            CW2Response <TransactionDto> response = TransactionService.Instance.removeDraft(model.Id);

            if (response.Status.Equals(AppConstant.SUCCESS))
            {
                MessageBox.Show(response.Message);
            }
        }
Beispiel #9
0
        /*
         * Saves the data into file system
         */
        public CW2Response <TransactionDto> save(TransactionDto dto)
        {
            CW2Response <TransactionDto> validated = validateSave(dto);

            if (validated.Status.Equals(AppConstant.ERROR))
            {
                Console.WriteLine("Validation Error : Saving transaction failed");
                return(validated);
            }

            //save local copy
            CW2Response <TransactionDto> saveDraftResponse = saveDraft(dto);

            if (saveDraftResponse.Status.Equals(AppConstant.ERROR))
            {
                Console.WriteLine("Saving Draft Failed..attepmpting the save on database");
            }

            //save data on DB
            Task saveToDbTask = Task.Run(() => {
                CW2Response <TransactionDto> saveToDBResponse = saveOnDB(dto);
                if (saveToDBResponse.Status.Equals(AppConstant.SUCCESS))
                {
                    //saving data to database success.
                    //remove the local copy.
                    Console.WriteLine("Record saved into the database successfully.");
                    CW2Response <TransactionDto> removeDraftResponse = removeDraft(saveDraftResponse.dto.Id);
                }
            });

            //CW2Response<TransactionDto> saveToDBResponse =  saveOnDB(dto);


            /* if (saveDraftResponse.Status.Equals(AppConstant.SUCCESS) && saveToDBResponse.Status.Equals(AppConstant.SUCCESS))
             * {
             *   saveToDBResponse.Message = "Record saved successfully";
             *   saveToDBResponse.Status = AppConstant.SUCCESS;
             * }
             * else if (saveDraftResponse.Status.Equals(AppConstant.SUCCESS) && saveToDBResponse.Status.Equals(AppConstant.ERROR))
             * {
             *   saveToDBResponse.Message = "System was unable to connect to the database. Record was saved as a draft";
             *   saveToDBResponse.Status = AppConstant.SUCCESS;
             * }
             * else if (saveDraftResponse.Status.Equals(AppConstant.ERROR) && saveToDBResponse.Status.Equals(AppConstant.SUCCESS))
             * {
             *   saveToDBResponse.Message = "Record saved successfully";
             *   saveToDBResponse.Status = AppConstant.SUCCESS;
             * }
             * else if (saveDraftResponse.Status.Equals(AppConstant.ERROR) && saveToDBResponse.Status.Equals(AppConstant.ERROR))
             * {
             *   saveToDBResponse.Status = AppConstant.ERROR;
             *   saveToDBResponse.Message = "Record saved failed";
             * }*/

            return(saveDraftResponse);
        }
Beispiel #10
0
        private CW2Response <TransactionDto> saveDraft(TransactionDto dto)
        {
            CW2Response <TransactionDto> response = new CW2Response <TransactionDto>();

            try
            {
                Cw2DataSet dataSet = DataSetProvider.Instance.getDataSet();

                TransactionRow transactionRow = null;

                if (dto.DbEntityId == 0) //Entity not saved to database.
                {
                    if (dto.Id != 0)     //Update
                    {
                        transactionRow = TransactionDataSetDao.Instance.findById(dto.Id);
                        TransactionTransformer.Instance.dtoToDataSetRow(dto, transactionRow);
                    }
                    else //create
                    {
                        transactionRow = dataSet.Transaction.NewTransactionRow();
                        TransactionTransformer.Instance.dtoToDataSetRow(dto, transactionRow);
                        dataSet.Transaction.AddTransactionRow(transactionRow);
                    }
                }
                else
                {
                    //Edit transaction from the database. Local copy has been removed
                    //need to create a new local copy.

                    transactionRow = dataSet.Transaction.NewTransactionRow();
                    TransactionTransformer.Instance.dtoToDataSetRow(dto, transactionRow);
                    dataSet.Transaction.AddTransactionRow(transactionRow);
                }

                dataSet.AcceptChanges();
                DataSetProvider.Instance.writeDataSet();

                response.dto     = TransactionTransformer.Instance.dataSetRowToDto(transactionRow);
                response.Status  = AppConstant.SUCCESS;
                response.Message = "Transaction local copy saved successfully";
            }
            catch (Exception e)
            {
                response.Status  = AppConstant.ERROR;
                response.Message = "DB Error : Unable to persist transaction draft";
                Console.WriteLine(e.StackTrace);
            }

            return(response);
        }
Beispiel #11
0
        public CW2Response <ContactDto> saveDraft(ContactDto dto)
        {
            CW2Response <ContactDto> response = new CW2Response <ContactDto>();

            try
            {
                Cw2DataSet dataSet = DataSetProvider.Instance.getDataSet();

                ContactRow contactRow = null;

                if (dto.DbEntityId == 0) //Entity not saved to database.
                {
                    if (dto.Id != 0)     //Update
                    {
                        contactRow = ContactDataSetDao.Instance.findById(dto.Id);
                        ContactTransformer.Instance.dtoToDataSetRow(dto, contactRow);
                    }
                    else //create
                    {
                        contactRow = dataSet.Contact.NewContactRow();
                        ContactTransformer.Instance.dtoToDataSetRow(dto, contactRow);
                        dataSet.Contact.AddContactRow(contactRow);
                    }
                }
                else
                {
                    //Edit contact from the database. Local copy has been removed
                    //need to create a new local copy.

                    contactRow = dataSet.Contact.NewContactRow();
                    ContactTransformer.Instance.dtoToDataSetRow(dto, contactRow);
                    dataSet.Contact.AddContactRow(contactRow);
                }

                dataSet.AcceptChanges();
                DataSetProvider.Instance.writeDataSet();

                response.dto     = ContactTransformer.Instance.dataSetRowToDto(contactRow);
                response.Status  = AppConstant.SUCCESS;
                response.Message = "Contact local copy saved successfully";
            }
            catch (Exception e)
            {
                response.Status  = AppConstant.ERROR;
                response.Message = "DB Error : Unable to persist contact draft";
                Console.WriteLine(e.StackTrace);
            }

            return(response);
        }
Beispiel #12
0
        private void onSaveButtonClick(object sender, EventArgs e)
        {
            model.ContactName = txtName.Text.Trim();
            model.Address     = txtAddress.Text.Trim();
            model.Email       = txtEmail.Text.Trim();
            model.Tel         = txtTel.Text.Trim();
            model.Type        = cmbType.Text.Trim();

            CW2Response <ContactDto> reponse = ContactService.Instance.save(model);

            showSuccessStatus(reponse.Message);
            if (reponse.Status.Equals(AppConstant.SUCCESS))
            {
                //populateGrid();
            }
        }
Beispiel #13
0
        private CW2Response <TransactionDto> validateSave(TransactionDto dto)
        {
            CW2Response <TransactionDto> response = new CW2Response <TransactionDto>();

            try
            {
                validateDateRange(dto);
                response.Status = AppConstant.SUCCESS;
            }
            catch (CW2DataValidationException e)
            {
                response.Status  = AppConstant.ERROR;
                response.Message = e.Message;
                Console.WriteLine(e.Message);
            }

            return(response);
        }
Beispiel #14
0
        private void onBtnDeleteClick(object sender, EventArgs e)
        {
            int    id     = Convert.ToInt32(this.selectedRow.Cells["Id"].Value);
            string status = Convert.ToString(this.selectedRow.Cells["Status"].Value);

            if (AppConstant.DRAFT.Equals(status))
            {
                CW2Response <ContactDto> reponse = ContactService.Instance.removeDraft(id);
                MessageBox.Show(reponse.Message);
            }
            else
            {
                CW2Response <ContactDto> reponse = ContactService.Instance.delete(id);
                MessageBox.Show(reponse.Message);
            }

            fetchDataByCriteria();
        }
Beispiel #15
0
        private CW2Response <TransactionDto> saveOnDB(TransactionDto dto)
        {
            CW2Response <TransactionDto> response = new CW2Response <TransactionDto>();

            try
            {
                Transaction transaction = null;

                if (dto.DbEntityId != 0) //Update
                {
                    transaction = TransactionDao.Instance.findById(dto.DbEntityId, false);
                    TransactionTransformer.Instance.dtoToDomain(dto, transaction);

                    if (!transaction.ExpireDate.Equals(dto.ExpireDate))
                    {
                        //recreate transaction instances
                        TransactionDao.Instance.clearTransactionInstances(dto.Id);
                        populateTransactionInstances(transaction, dto);
                        //transaction.TransactionInstances.Clear();
                    }
                }
                else //create
                {
                    transaction = new Transaction();
                    TransactionTransformer.Instance.dtoToDomain(dto, transaction);
                    transaction.Id = 0;
                    populateTransactionInstances(transaction, dto);
                }

                transaction = TransactionDao.Instance.save(transaction);

                response.dto     = TransactionTransformer.Instance.domainToDto(transaction);
                response.Status  = AppConstant.SUCCESS;
                response.Message = "Transaction saved successfully";
            }
            catch (Exception e)
            {
                response.Status  = AppConstant.ERROR;
                response.Message = "DB Error : Unable to persist transaction entity";
                Console.WriteLine(e.StackTrace);
            }

            return(response);;
        }
Beispiel #16
0
        public CW2Response <ContactDto> delete(int id)
        {
            CW2Response <ContactDto> response = new CW2Response <ContactDto>();

            try
            {
                ContactDao.Instance.delete(id);
                response.Status  = AppConstant.SUCCESS;
                response.Message = "Record deleted successfully";
            }
            catch (Exception e)
            {
                response.Status  = AppConstant.ERROR;
                response.Message = "Internal System Failure";
                Console.WriteLine(e.StackTrace);
            }

            return(response);
        }
Beispiel #17
0
        private void fetchDataByCriteria()
        {
            TransactionDto dto = new TransactionDto();

            if (txtTitle.Text.Trim().Length > 0)
            {
                dto.Title = txtTitle.Text;
            }

            if (cmbType.Text.Trim().Length > 0)
            {
                dto.Type = cmbType.Text;
            }

            if (dtpDate.Value != null)
            {
                //dto.CreatedDate = dtpDate.Value;
            }
            else
            {
                // dto.CreatedDate = null;
            }

            dataGridTransaction.AutoGenerateColumns = false;

            var dataList = new ArrayList();

            //Add Draft data first
            CW2Response <TransactionDto> response1 = TransactionService.Instance.getAllTransactionsFromDataSet();

            dataList.AddRange(response1.dataList);

            //Add DB saved data
            CW2Response <TransactionDto> response = TransactionService.Instance.searchTransactionByCriteria(dto);

            dataList.AddRange(response.dataList);

            dataGridTransaction.DataSource = dataList;

            reset();
        }
Beispiel #18
0
        public CW2Response <ContactDto> removeDraft(int id)
        {
            CW2Response <ContactDto> response = new CW2Response <ContactDto>();

            try
            {
                Cw2DataSet dataSet    = DataSetProvider.Instance.getDataSet();
                ContactRow contactRow = dataSet.Contact.FindById(id);
                contactRow.Delete();
                dataSet.AcceptChanges();
                DataSetProvider.Instance.writeDataSet();

                response.Status  = AppConstant.SUCCESS;
                response.Message = "Contact Draft Remove Successfully";
            }
            catch (Exception e)
            {
                response.Status  = AppConstant.ERROR;
                response.Message = "Transaction Draft Remove Failed";
                Console.WriteLine(e.StackTrace);
            }

            return(response);
        }
Beispiel #19
0
        public CW2Response <TransactionDto> getAllTransactionsFromDataSet()
        {
            CW2Response <TransactionDto> response           = new CW2Response <TransactionDto>();
            List <TransactionDto>        transactionDtoList = new List <TransactionDto>();

            try
            {
                List <TransactionRow> transactionRows = TransactionDataSetDao.Instance.getAllTransactions();

                foreach (var transactionRow in transactionRows)
                {
                    transactionDtoList.Add(TransactionTransformer.Instance.dataSetRowToDto(transactionRow));
                }
                response.Status = AppConstant.SUCCESS;
            }
            catch (Exception e)
            {
                response.Status  = AppConstant.ERROR;
                response.Message = "Internal System Failure";
            }

            response.dataList = transactionDtoList;
            return(response);
        }
Beispiel #20
0
        private void onBtnSaveTransactionClick(object sender, EventArgs e)
        {
            if (ValidateChildren(ValidationConstraints.Enabled))
            {
                model.Title       = txtTxnTitle.Text;
                model.Amount      = Convert.ToDouble(txtTxnAmount.Text);
                model.CreatedDate = dtpDate.Value;

                //set the type field.

                if (rBtnIncome.Checked)
                {
                    model.Type = AppConstant.INCOME;
                }
                else
                {
                    model.Type = AppConstant.EXPENSE;
                }

                //set occurence field

                if (rBtnOneOff.Checked)
                {
                    model.Occurence = AppConstant.ONE_OFF;
                }
                else
                {
                    model.Occurence = AppConstant.RECURRENCE;
                }

                model.ExpireDate = dtpExpireDate.Value;

                if (cmbRecurrenceType.SelectedItem != null)
                {
                    model.RecurrenceType = cmbRecurrenceType.SelectedItem.ToString();
                }

                if (txtDay.Text.Trim().Length > 0)
                {
                    model.OnDate = Convert.ToInt32(txtDay.Text);
                }
                else
                {
                    model.OnDate = null;
                }

                if (cmbMonth.SelectedItem != null)
                {
                    model.OnMonth = cmbMonth.SelectedItem.ToString();
                }

                model.ExpireDate = dtpExpireDate.Value;

                CW2Response <TransactionDto> response = TransactionService.Instance.save(model);

                if (response.Status.Equals(AppConstant.ERROR))
                {
                    MessageBox.Show(response.Message);
                }
                else
                {
                    MessageBox.Show(response.Message);
                    reset();
                }
            }
        }