public int addVoucherCategory(VoucherCategory category) { SSGetService getService = new SSGetService(); SSUpdateService updateService = new SSUpdateService(); VoucherCategory existingCategory = getService.getVoucherByName(category.name); if (existingCategory.name == null) { using (SqlCommand command = new SqlCommand("INSERT INTO ss_voucher_categories(name)VALUES(@name)")) { command.Parameters.AddWithValue("@name", category.name); int response = service.execute(command); if (response > 0) { this.addLog(new Log() { type = "Add Voucher Category", statement = command.CommandText, description = "Created voucher category " + existingCategory.name, }); } return(response); } } else { return(-101); } }
public int MakeVoucher(Voucher voucher) { SSGetService getService = new SSGetService(); VoucherCategory category = getService.getVoucherByName(voucher.type); if (category.name != null) { DataTable data = service.get("select * from ss_account"); if (data.Rows.Count > 0) { DataRow row = data.Rows[0]; int balance = row.Field <int>("balance"); int previusBalance = balance; if (balance >= voucher.amount) { balance = balance - voucher.amount; using (SqlCommand command = new SqlCommand("update ss_account set balance=@balance, previous_balance=@previous_balance")) { command.Parameters.AddWithValue("@balance", balance); command.Parameters.AddWithValue("@previous_balance", previusBalance); if (service.execute(command) > 0) { User user = app.getSession(); using (SqlCommand addCommand = new SqlCommand("INSERT INTO ss_vouchers(user_id,amount,amount_in_words,type,description)VALUES(@user_id,@amount,@amount_in_words,@type,@description)")) { addCommand.Parameters.AddWithValue("@user_id", user.id); addCommand.Parameters.AddWithValue("@amount", voucher.amount); addCommand.Parameters.AddWithValue("@amount_in_words", app.toWordsOf(voucher.amount)); addCommand.Parameters.AddWithValue("@type", voucher.type); addCommand.Parameters.AddWithValue("@description", voucher.description); return(service.execute(addCommand)); } } else { return(-1); } } } else { return(-402); } } else { return(-403); } } else { return(-404); } }