Example #1
0
        public async Task <ResultModel> CreateExpenseSubType(ExpenseSubTypeVm expenseSubTypeVm)
        {
            try
            {
                var entity = new ExpenseSubType
                {
                    ExpenseTypeId      = expenseSubTypeVm.ExpenseTypeId,
                    ExpenseSubTypeName = expenseSubTypeVm.ExpenseSubTypeName,


                    CreatedBy  = _currentUserService.UserId,
                    CreateDate = _dateTime.Now,
                };

                await _context.L_EXPENSE_SUB_TYPE.AddAsync(entity);

                await _context.SaveChangesAsync();

                return(new ResultModel
                {
                    Result = true,
                    Message = NotificationConfig.InsertSuccessMessage($"{expenseSubTypeVm.ExpenseSubTypeName}"),
                    Id = entity.ExpenseSubTypeId.ToString()
                });
            }
            catch (Exception)
            {
                return(new ResultModel {
                    Result = false, Message = NotificationConfig.InsertErrorMessage($"{expenseSubTypeVm.ExpenseSubTypeName}")
                });
            }
        }
Example #2
0
        private List <ExpenseSubType> selectExpenseSubTypes(SqlCommand cmd, int parentID)
        {
            cmd.CommandType = CommandType.StoredProcedure;
            SqlConnection con = cmd.Connection;

            cmd.Parameters.AddWithValue("@ParentID", DALHelper.getNullORValue(parentID));
            List <ExpenseSubType> ExpenseSubTypes = new List <ExpenseSubType>();

            con.Open();
            using (con)
            {
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    ExpenseSubTypes = new List <ExpenseSubType>();
                    while (dr.Read())
                    {
                        //ID
                        //Parent Category (ID)
                        //Parent Category (Desc)
                        //Description (of sub type)
                        //Comments

                        ExpenseCategory expCategory = new ExpenseCategory
                        {
                            ID          = Convert.ToInt32(dr[1]),
                            Description = Convert.ToString(dr[2])
                        };

                        ExpenseSubType expSubType = new ExpenseSubType
                        {
                            ID          = Convert.ToInt32(dr[0]),
                            Description = Convert.ToString(dr[3])
                        };

                        expSubType.ParentCategory = expCategory;

                        ExpenseSubTypes.Add(expSubType);
                    }
                }
            }
            return(ExpenseSubTypes);
        }
Example #3
0
        public async Task <ResultModel> UpdateExpenseSubType(UpdateExpenseSubTypeVm updateExpenseSubTypeVm)
        {
            try
            {
                if (updateExpenseSubTypeVm.ExpenseSubTypeId > 0)
                {
                    var entity = new ExpenseSubType
                    {
                        ExpenseSubTypeId   = updateExpenseSubTypeVm.ExpenseSubTypeId,
                        ExpenseTypeId      = updateExpenseSubTypeVm.ExpenseTypeId,
                        ExpenseSubTypeName = updateExpenseSubTypeVm.ExpenseSubTypeName,

                        UpdateBy   = _currentUserService.UserId,
                        UpdateDate = _dateTime.Now,
                    };

                    _context.L_EXPENSE_SUB_TYPE.Update(entity);
                    await _context.SaveChangesAsync();

                    return(new ResultModel
                    {
                        Result = true,
                        Message = NotificationConfig.UpdateSuccessMessage($"{updateExpenseSubTypeVm.ExpenseSubTypeName}"),
                        Id = entity.ExpenseSubTypeId.ToString()
                    });
                }

                else
                {
                    return(new ResultModel {
                        Result = false, Message = NotificationConfig.NotFoundMessage($"{updateExpenseSubTypeVm.ExpenseSubTypeName} ")
                    });
                }
            }
            catch (Exception)
            {
                return(new ResultModel {
                    Result = false, Message = NotificationConfig.UpdateErrorMessage($"{updateExpenseSubTypeVm.ExpenseSubTypeName} ")
                });
            }
        }
Example #4
0
        private List <Expense> selectExpenses(SqlCommand cmd)
        {
            cmd.CommandType = CommandType.StoredProcedure;
            SqlConnection  con      = cmd.Connection;
            List <Expense> Expenses = new List <Expense>();

            con.Open();
            using (con)
            {
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    Expenses = new List <Expense>();
                    while (dr.Read())
                    {
                        #region List of columns returned by Procedure - Just for Reference of Front-End Developer in future - Dec 30th, 2014.

                        //ID
                        //Date
                        //Category (ID)
                        //Category (Desc)
                        //SubCategory (ID)
                        //SubCategory (Desc)
                        //Entered By (ID)
                        //Entered By (Desc)
                        //Amount
                        //Comments

                        #endregion

                        ExpenseCategory expCategory = new ExpenseCategory
                        {
                            ID          = Convert.ToInt32(dr[2]),
                            Description = Convert.ToString(dr[3])
                        };

                        ExpenseSubType expSubType = new ExpenseSubType
                        {
                            ID          = Convert.ToInt32(dr[4]),
                            Description = Convert.ToString(dr[5])
                        };

                        expSubType.ParentCategory = expCategory;

                        User usr = new User
                        {
                            ID       = Convert.ToInt32(dr[6]),
                            UserName = Convert.ToString(dr[7])
                        };

                        Expense exp = new Expense
                        {
                            ID          = Convert.ToInt32(dr[0]),
                            ExpenseDate = Convert.ToDateTime(dr[1]),
                            Amount      = Convert.ToInt32(dr[8]),
                            Comments    = Convert.ToString(dr[9])
                        };

                        exp.SubType   = expSubType;
                        exp.EnteredBy = usr;

                        Expenses.Add(exp);
                    }
                }
                return(Expenses);
            }
        }
        public void Save()
        {
            expHandler = new ExpensesHandler();

            Expense exp = new Expense();

            #region Validation for valid Expenditure data

            //Check if all text boxes are empty

            IEnumerable <TextBox>  textBoxcollection  = EntryGrid.Children.OfType <TextBox>();
            IEnumerable <ComboBox> comboBoxcollection = EntryGrid.Children.OfType <ComboBox>();

            foreach (TextBox box in textBoxcollection)
            {
                if (box.Name == "textBoxComments")
                {
                    //ignore
                }

                else
                {
                    if (string.IsNullOrWhiteSpace(box.Text))
                    {
                        MessageBox.Show("Kindly Fill all the boxes. (Only Comments are Optional)");
                        return;
                    }
                }
            }

            foreach (ComboBox box in comboBoxcollection)
            {
                if (box.SelectedIndex == -1)
                {
                    MessageBox.Show("Kindly Select all the fields");
                    return;
                }
            }


            #endregion

            //Inserting values in object

            exp.Amount      = Convert.ToInt32(textBoxAmount.Text);
            exp.ExpenseDate = DateTime.Now;
            exp.Comments    = textBoxComments.Text;

            expCategory = (ExpenseCategory)(expenditureTypeComboBox.SelectedItem);

            expSubType = (ExpenseSubType)expenditureSubTypeComboBox.SelectedItem;
            //Below Line is Unnecessary - 1 Jan
            expSubType.ParentCategory = expCategory;
            exp.SubType = expSubType;

            User usr = GlobalSettings.CurrApplictionUser;

            try
            {
                expHandler.AddExpense(exp, usr);
            }
            catch (Exception exc)
            {
                MessageBox.Show("Database Error!", exc.Message);
                return;
            }

            //Enter into Transaction List - Added 01 Jan
            //Experimental yet - 11:25

            //Commented on March 12
            //GlobalSettings.TransList.Add(new DBTransaction(DateTime.Now, GlobalSettings.CurrApplictionUser));

            //Clear all the TextBoxes

            foreach (TextBox box in textBoxcollection)
            {
                box.Text = "";
            }

            foreach (ComboBox box in comboBoxcollection)
            {
                box.SelectedIndex = -1;
            }

            //MessageBox.Show("Successfully Saved!");

            //mwin = MainWindow.a

            //mwin.expenditureFrame.Refresh();
        }